Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this questionI have a page display some posts categories. So I want display before all post in my category 1 then, the others categories...
So I want have: - display all posts in category 1 with descendent data after all posts I want display all other categories
thanks
I find the solution: So I have the first query args:
$prima = array(
'post_type' => 'post',
'order' => 'DESC',
'orderby' => 'date',
// 'cat' => 41,
'category__in' => array('41'),
'post_status' => 'publish',
'suppress_filters' => 0,
'nopaging' => true,
);
The second query args
$seconda = array(
'post_type' => 'post',
'order' => 'DESC',
'orderby' => 'date',
// 'cat' => 41,
'category__in' => array('42,43'),
'post_status' => 'publish',
'suppress_filters' => 0,
'nopaging' => true,
);
So I find the post ids from the 2 queries and I add in the same array
// unique array
$array_primo_secondo = array();
// first loop
if ($query_prima->have_posts()) : while ($query_prima->have_posts()) : $query_prima->the_post();
$post_id_prima = get_the_ID();
$array_primo_secondo[] = $post_id_prima;
endwhile;
endif;
// second loop
if ($query_seconda->have_posts()) : while ($query_seconda->have_posts()) : $query_seconda->the_post();
$post_id_seconda = get_the_ID();
$array_primo_secondo[] = $post_id_seconda;
endwhile;
endif;
Now I have the array with all the ID So I can do the last query
$args = array(
// all the post in my array
'post__in' => $array_primo_secondo,
// I have the original pagination
'paged' => $paged,
'suppress_filters' => 0,
// I have the order in the array
'orderby' => 'post__in',
);
$wp_query = new WP_Query($args);
Thanks