Reputation: 181
I am retrieving some post and to show post on first come first basic. Now I want to show those post on the top which are posted by admin and the rest post by non admin will come after admin posts.
the code I am using in php is:
$tit = get_the_title();
$args = array(
'post_type' =>'contribute',
'numberposts' => 100,
'meta_key' => 'portfolio',
'meta_value' => $tit ,
);
$slides = get_posts($args);
?>
<ul id="myList">
<?php foreach($slides as $post) : setup_postdata($post); ?>
<li>the post will go here</li>
<?php endforeach; wp_reset_postdata(); ?>
Upvotes: 0
Views: 71
Reputation: 1817
To display posts from admin first and then from non-admin, you have to call get_posts twice.
Once with :-
$args = array(
'post_type' =>'contribute',
'numberposts' => 100,
'meta_key' => 'portfolio',
'meta_value' => $tit ,
'author' => '123' // where 123 is ID of your admin author
);
The other will be :-
$args = array(
'post_type' =>'contribute',
'numberposts' => 100,
'meta_key' => 'portfolio',
'meta_value' => $tit ,
'author' => '-123' // display posts except admin author
);
Upvotes: 1
Reputation: 50798
Add the author
method to your array:
$args = array(
'post_type' =>'contribute',
'numberposts' => 100,
'meta_key' => 'portfolio',
'meta_value' => $tit,
'author_name' => 'Administrator' //add this, change Administrator to your name
);
Upvotes: 0