I am trying to retrieve a list of IDs to remove from the search query based off of a WP_Query. For whatever reason the WP_Query is not displaying an array of IDs even though I know that post id 373 has the correct conditions of the query.
remove_action('pre_get_posts','exclude_pages_from_search');
$hidePages = new WP_Query( array (
'meta_key' => 'edit_screen_sitemap',
'meta_value' => 'hide',
'fields' => 'ids'
));
$hidePageIds = array($hidePages->posts);
$hidePageIdss = array($hidePages);
var_dump($hidePageIds); // array(1) { [0]=> array(0) { } }
var_dump($hidePageIdss); // displays query array
add_action('pre_get_posts','exclude_pages_from_search');
function exclude_pages_from_search($query) {
if ( !is_admin() ) {
if ( $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post__not_in', array($hidePages->posts));
}
}
}
}