In a past blog post I explained why featuring posts using a taxonomy term is much more performant than using a meta query. The comment I get from people is “that’s awesome, but using tags to feature a post is not a good user experience”. I agree, attaching a “featured” tag to featured posts, while performant is not a good experience for users because it leaves room for error on the admin side and shows the “featured” tag to users on the front end (if you are listing your tags).
Thankfully, there is a much better way to do this. We can create a small meta box with a “Featured Post” checkbox. This checkbox will add/remove a term in a hidden taxonomy from the post. Here is what the meta box will look like in WordPress 3.9:
I will take you through the code necessary to set this up. First we need to register a private taxonomy for internal use:
Querying for posts on the front end is super easy! Here is an example query:
$query = new WP_Query( array(
‘tl_post_options’ => ‘tl_featured’
‘post_status’ => ‘publish’,
‘post_type’ => ‘post’,
Last year I did a presentation at WordCamp Orange County, WordCamp Birmingham, WordCamp Toronto, and WordCamp Providence called “What You Missed in Computer Science”. I have a Computer Science degree which I believe has provided me with some tools to think about problems in a certain way. This presentation will teach you about some of those tools, specifically Big-Oh Notation and race conditions. I will frame these Computer Science topics in terms of WordPress.
You can see a video recording of me giving the talk here at WordCamp Providence. I am reposting the slides on SlideShare since they seem to have disappeared: