Dynamic meta_query depending on query var paramters in url Wordpress custom post type

409 Views Asked by At

In my custom post type i want to filter depending on the parameters in the url. For example ?car=yellow&foo=1 refer to meta query key and value. The key and value's are the extra fields. What makes it extra difficult is that

This is what my loop looks like right now:

$args = array(
    'post_type'=>'glas', // Your post type name
    'posts_per_page' => 9,
    'paged' => $paged,
);

$loop = new WP_Query( $args ); ?>
<?php if($loop->have_posts()): ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php echo get_field('type_glas'); ?> <?php echo get_field('uitvoering_glas'); ?><br>


    <?php endwhile; ?>
    <?php $total_pages = $loop->max_num_pages; ?>
    <?php if ($total_pages > 1) : ?>
        <?php
        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
        ?>
    <?php endif; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
0

There are 0 best solutions below