N
N
night_breeze2017-05-04 14:51:54
RSS
night_breeze, 2017-05-04 14:51:54

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

1 answer(s)
D
Dimox, 2017-05-11
@Dimox

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' );

You need to paste it in functions.php .
add_to_rss is the name of the field in the ACF.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question