Answer the question
In order to leave comments, you need to log in
How to set up an rss feed in WP?
It is necessary to make sure that not all entries are added to the rss feed. Namely, from the admin panel, if the user checks the box "Add to rss" when adding news, then this news will be added to rss, otherwise the news will not be published there. How can this be implemented? (tick made with ACF)
Answer the question
In order to leave comments, you need to log in
Try it:
function add_to_rss($query) {
if (is_admin()) {
return $query;
}
$include = array();
if ( $query->is_main_query() && is_feed() ) {
$posts = get_posts(array(
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'добавить_в_rss',
'value' => '1',
'compare' => '=',
),
),
));
foreach($posts as $post) {
$include[] = $post->ID;
}
$query->set('post__in', $include);
}
return $query;
}
add_filter( 'pre_get_posts', 'add_to_rss' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question