How can I hide posts from some category with some ID from main page of my site? I need solution like filter:
function exclude_post($query) {
if ($query->is_home) {
...
}
return $query;
}
add_filter('pre_get_posts', 'exclude_post');
Can somebody provide an example?
Use
$query->set( $query_var, $value );
where $query_var is the variable you want to add/update in query. So put this inside your condition:Remember is good practice put in condition a check to
$query->is_main_query()
.pre_get_posts
is an action hook so you have to changeadd_filter
toadd_action
. An action hook doesn't return a value, a filter does.Example
UPDATE
According to the new details emerging by the question,in order to exclude some posts in feeds stream, but not in category archive, the conditional check might look like:
OR
Hope it helps!
you can also use the following way to exclude the a category from post query
You can use simple exclude in the query parameters :-
Its only sample , how to you exclude.
Hop it work..