Show post first in loop based upon meta key, in array of multiple categories
-
I am trying to achieve the following. Using the wordpress theme newspaper, a custom block is displaying the four most recent posts from a couple of categories, which are set in a tagdiv composer that came with the theme.
These blocks offer sorting options, which are built in the theme as “cases” or wp query arguments. These cases can then be selected and applied to the blocks where you set number of posts, categories on which to show posts fom etc.
I however need the latest post from one category (called win win win), which if set to that category, automatically checks the custom field “wedstrijd” to true, with the thought of using this “true/false” boolean, to show up as the first post of the four.
So, if there is a contest, the first post is always that contest post, the other three are to be filled up with the most recent posts from an array of categories.
Until the contest post is deleted, it should remain on the top position while other content is being added, which thus will have a later publishing date. That contest category will always have just one active published post.
I have tried the following but sadly I only get to show the single post with the key wedstrijd set to true. Anyone out there who can help me with this ?
Sticky posts are sadly not an option since the theme doesn’t support this.
The categories are set in the tagdiv composer of the site, which are 4,5,9,433,43,47,36,18,17,427,790,31648, with 31648 being the contest category. I have already tried setting the categories in the query below but this doesn’t work or override the settings in the tagdiv composer.
case 'winfirst': $wp_query_args['meta_query'] = array( 'relation' => 'OR', 'query_one' => array( 'key' => 'wedstrijd', 'compare' => '=', 'value' => '1' ), 'query_two' => array( 'key' => 'wedstrijd', 'compare' => '=', 'value' => '', ), ); $wp_query_args['orderby'] = array( 'query_one' => 'ASC', 'query_two' => 'DESC');
- The topic ‘Show post first in loop based upon meta key, in array of multiple categories’ is closed to new replies.