WP_Query order posts by category
In a custom WP_Query I want to order posts by category. I mean that I want to show posts with term_id=1291
first and then show other posts.
when I use two WP_Query , I cant use pagination.
edited
I tried this at first. I thought when I use post__in
, wp_query
,keep posts order in post__in
.
$c_cat=$_GET[c_cat]
$query1 = new WP_Query(array(
'tax_query' = array(
array(
'taxonomy' = 'category',
'field' = 'term_id',
'terms' = $c_cat,
)
)
));
$query1_ids=array();
foreach ($query1-posts as $p){
array_push($query1_ids,$p-ID);
}
//new query, using post__in parameter
$finalQuery = new WP_Query(array('post__in' = $query1_ids));
Topic order wp-query plugin-development theme-development Wordpress
Category Web