I have some automatic generated posts in my system, wp_posts
table has additional field auto
, by default this field is NULL, but for my specific posts it have some value. I don't wont to show such posts on main page, how can I hide them?
I think I need something like:
function exclude_post($query) {
if ($query->is_home) {
...
}
return $query;
}
add_filter('pre_get_posts', 'exclude_post');
how can I add conditions like SQL "auto IS NOT NULL"
?
If you were following other users suggestions and changed to post meta instead of an additional column in the posts table you could add:
$query->set( 'meta_query', array(
array(
'key' => 'meta_key_for_auto',
'compare' => 'NOT EXISTS',
),
) );
If you're going to stick with the column in the posts table then pre_get_posts probably isn't the best hook to use. Instead look at posts_where. http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where