Y
Y
Ysery2020-02-07 16:10:51
RSS
Ysery, 2020-02-07 16:10:51

Display in Wordpress RSS only those posts that have the value of the custom field "add_in_rss" assigned, how?

Good day

Please tell me how in WordPress to show in the RSS feed only those posts that specify the value of a custom field, for example, add_in_rss and the value yes 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.

Found this code :

// 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


I entered it in the WordPress feed-rss2.php file responsible for RSS (only the exclamation point was removed so that there was not an exclusion of the record, but an insertion of the record if it had an arbitrary field)

...do_action( 'rss2_head' );
        
        while ( have_posts() ) :
        	the_post();
    		$meta = get_post_meta($post->ID, "add_in_rss", false);
    		if($meta = "yes"){
        	?>
        <item>
        	<title><?php the_title_rss(); ?><....
    ....
    ....p echo get_comments_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; ?>...


But why doesn't it work :-(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-02-07
@Kozack

Use the filter
https://wp-kama.ru/hook/pre_get_posts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question