Exclude Posts from RSS Feed that have an ACF True/False Field set to TRUE

Hi all,

Bit stuck on this one. I've been trying to exclude specific posts that have the ACF True/False field set to TRUE from the RSS Feed.

Currently the function I have is:

function qr_rssremove( $where, $wp_query = NULL ) {

`global $wpdb;`



`if ( !$wp_query ) global $wp_query; if ( $wp_query->is_feed ) {`

	`$qr_args = array(`

		`'meta_query' => array(`

array(

'key' => 'qr_code',

'value' => '1',

'compare' => '=='

)

		`),`

	`);`



	`$posts = get_posts( $qr_args );`



	`if ( $posts ) {`

		`foreach( $posts as $post ) {`

$exclude .= $post->ID . ',';

		`}`

	`}`



	`$exclude = substr( $exclude,0, strlen( $exclude )-1 );`



	`$where .= ' AND $wpdb->posts.ID NOT IN ( ' . $exclude . ')';`

`}`



`return $where;`

}

add_filter( 'posts_where', 'qr_rssremove', 1, 4 );

But when I go to the /feed/ it seems to remove all of the posts from the RSS feed instead of the posts that specifically have the "qr_code" ACF T/F field set to TRUE

Decided to go this route because I didn't want to assign and create a custom category for excluding these posts specifically from the RSS feed

Any help would be greatly appreciated!

Posted Jun 8, 2024, 5:39 PM UTC

10

Comments aren't archived yet

Comments for this period haven't been loaded into the archive yet.