Hello,
I have a 'News' category and I would like to be able to make certain posts in that category 'Featured' or 'Sticky'.
To make a post 'Featured', I add a Custom Field 'Featured News' with the value 'true'. For normal posts, there is no Custom Field.
I could not get WP_query to sort the posts properly so what I tried was doing two separate queries, the first to get featured posts and the second to get non featured posts. However, it seems that if the Custom Field is not present at all, the post gets ignored. Here is my code:
$newsQuery = array( 'category_name' => 'news',
'meta_query' => array( 'key' => 'Featured News', 'compare' => '!=', 'value' => 'true' ),
'posts_per_page' => 4,
'orderby' => 'date',
'order' => 'desc' );
It would seem that in order for this to work I would have to give non-featured posts the Custom Field 'Featured News' with a value 'false'. I was hoping that if the field is not present, a value of 'false' would be assumed. Is there any way to make it work that way?
Thanks!