2

How to show the posts of some category first, and then all other posts that does not belong to that category?

I have logic that get the category and reorder the posts. But i don't know how to use. Please help.

$args = array(
    'post_type' => 'event',
    'meta_key'  => '_event_end_date',
    'meta_compare' => '>',
    'meta_value' => $today,
    'order' => 'DESC',
    'posts_per_page' => '10'
);
$loop = new WP_Query( $args );
  • 1
    Can you provide your code. :) – ksr89 May 26 '14 at 5:50
  • @ksr89 see updated question – Nisham Mahsin May 26 '14 at 5:53
  • In your code their is nothing about category only about meta_key and meta_value. – ksr89 May 26 '14 at 6:06
  • i want to list all category.but some category comes to first. – Nisham Mahsin May 26 '14 at 6:08
  • It can not be done with one query. You will need to use two different queries. – тнє Sufi May 26 '14 at 7:01
2

You can't do it in one query. You have to add second query to show the posts of another category. Like

$args = array(
    'post_type' => 'event',
    'cat' => 4 //category id.
);
$posts = new WP_Query( $args ); // Get all the posts category which you want to show first.

$args2 = array(
    'post_type' => 'event',
    'cat' => -4 //Display all posts exclude this category.
);
$posts = new WP_Query( $args2 ); // Get all the posts category which you want to show second.

For reference check here: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.