Y
Y
Ysery2019-11-29 17:08:25
RSS
Ysery, 2019-11-29 17:08:25

Display a post in WordPress RSS only if it has a custom field value entered, how to do it?

Good day
, Please tell me how in WordPress to show in the RSS feed only those posts that have a custom field value, for example, rss-on and a value of 1 for it.
So that all published / updated articles do not get into the RSS, but only the specified ones. Such custom RSS will turn out in the end.
I found this code here :

// Loop starts here
while (have_posts()) : the_post();
// Get the meta field
$meta = get_post_meta($post->ID, "Meta Name", false);
// Do no show post if the meta equals "Meta Value"
if($meta != "Meta Value"){
// Content Here
}
endwhile;
// Loop ends

And in the feed-rss2.php file I saw this code, where it seems like you can enter it:
while ( have_posts() ) :
    the_post();
    ?>
  <item>
    <title><?php the_title_rss(); ?></title>
    <link><?php the_permalink_rss(); ?></link>
    <?php if ( get_comme...
...
.....ments_number(); ?></slash:comments>
    <?php endif; ?>
    <?php rss_enclosure(); ?>
    <?php
    /**
     * Fires at the end of each RSS2 feed item.
     *
     * @since 2.0.0
     */
    do_action( 'rss2_item' );
    ?>
  </item>
  <?php endwhile; ?>

How to edit it correctly (in the code above, if there is a record of an arbitrary field, an exception occurs, but you can do the reverse algorithm, like removing the exclamation mark for this?) and enter it in the RSS feed generation code below? And yes, when writing an article, in the input menu of an arbitrary field, what needs to be entered in the Name and Value that would work.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question