Hi @webcodeslinger:
Here’s what a basic MySQL query for loading News and Events would look like (this is greatly simplified from what WordPress actually does):
SELECT * FROM wp_posts WHERE post_type IN ('news','events')
What you want instead is something like this (there are more performant ways to do this in MySQL but they are more complex in WordPress and for most sites you’ll never notice a difference):
SELECT * FROM wp_posts WHERE post_type IN ('news','events')
OR (post_type="stories" AND ID IN
(SELECT post_id FROM wp_postmeta WHERE meta_key='mark-as-news')
)
So…to add that extra SQL to your main loop’s query use a 'posts_where'
hook. You can put the following hook code into your theme’s functions.php
file (at the bottom of the file will do) or in one of the .php
files of a plugin if you are creating a plugin:
add_action('posts_where','yoursite_posts_where',10,2);
function yoursite_posts_where($where,$query) {
global $wp_the_query;
if (is_home() && $query===$wp_the_query) { // This means home page and the main loop
global $wpdb;
$where .= " OR ({$wpdb->posts}.post_type="actor" AND " .
"{$wpdb->posts}.ID IN (" .
"SELECT post_id FROM {$wpdb->postmeta} " .
"WHERE meta_key='mark-as-news')) ";
}
return $where;
}