One of the tags of todays work was using meta_query along with custom post types to ensure that we’re displaying the correct post content.

The brief was to have a custom post type for event speakers but with individual speakers being selected as ‘featured speakers’, in this job it was H.R.H. Prince Turki Bin Nasser Bin Abdulaziz who had to appear above the other speakers in the list for obvious reasons.

The Miramedia speakers system uses a custom post type to build the list.

The simplest way to put this into practice is using the meta_query inside the wp_query statement as follows

$args = array(
'post_type' => 'speakers',
'meta_query' => array(
     'key' => 'speaker_featured',
     'value' => 'true',
     'compare' => '='

$query = new WP_Query( $args );
Run the loop!

This runs a check to look for any posts in the speakers post type to see if a checkbox for ‘speaker_featured’ is checked on or not. If it is then it it will display that speaker. In this case this would be the prince and places him at the top.

Then to run through the other speakers just amend the ” compare => ‘=’ ” to be “compare => ‘!=’ “.

Obviously this is a slightly dummed down version of the query but you get the  gist!

I’ve not sent it live just yet but if you want to check the site out it’s here: