Get post ID using custom field value
-
I am using a function to exclude certain posts from the main site feed using post IDs. It’s working by directly inputting the post ID in the function, but when I tried to do the same by using custom fields, it is not working.
This is the function:
function exp_post($query) { global $wpdb; $pid = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'excludefeed'"; $posts = $wpdb->get_results($pid); foreach( $posts as $post ) { $exclude[] = $post->ID; } if ( $query->is_feed) { $query->set('post__not_in', $exclude ); } return $query; } add_filter( 'pre_get_posts', 'exp_post' );
What seems to be the problem?
- The topic ‘Get post ID using custom field value’ is closed to new replies.