I have number of posts in post_type="post". I want to display all posts using WP_query on one page but those posts have customfield name="pinned_to_top" that should come first in loop and other posts without this custom field will come down.
I have tried to use of orderby but i can't do that.
I am using this code but it will give me posts only those have custom field="pinned", not other posts.
$query = array(
'category_name' => 'blog',
'paged'=> $paged,
'meta_query' => array(
array(
'key' => 'pinned',
'value' => 'yes',
'compare' => 'OR',
),
),
'posts_per_page' => '10',
);
$wp_query = new WP_Query($query);
Main motive to add this custom field is that, I want some Important posts at the top in LOOP.
Let me know if anyone have experienced it?
pinned_to_top, and in the second exlude those. - vaso123usortto sort the returned$postsbefore the loop - Pieter Goosen