mercredi 6 mai 2015

WordPress | Sortby & filter - Archive page

My code:

<?php
$the_key = 'upsidedate';  // The meta key to sort on
$args = array(
   'meta_key' => $the_key,
   'orderby' => 'meta_value',
   'order' => 'ASC',
);
global $wp_query;
query_posts(
        array_merge(
                $wp_query->query,
                $args
        )
);
?>
            <?php 
                if (have_posts()) : while (have_posts()) : the_post() ;

                    get_template_part('post', 'archive');
                endwhile;
                
                else :
                    get_template_part('post', 'noresults');
                endif; 
                
                get_template_part('navigation');
            ?>

What is doing now? its order by the custom field "upsidedate".

I want to order by the custom field "upsidedate" and filter by the custom field "done", I mean only if the value on "done" is "no" - it will show the post on archive.

Should be something like that:

$the_query = new WP_Query( array( 'meta_key' => 'done', 'meta_value' => 'no' ) ); 

But I cant use meta_key twice. How can I do that?

Aucun commentaire:

Enregistrer un commentaire