Filter certain page by ID from search result

Hi,

I have issue in filtering out certain pages by ID from search result.

I want to exclude both selected pages based on the IDs, and all pages that are set to noindex.

I follow the code snippet from https://community.algolia.com/wordpress/indexing-flow.html#indexing-decision

It works for Sudan pages, but does not work for Afghanistan pages. All on-page settings are similar, set to index. What am I missing here?

Here is my code:


/**
 * Don't index pages if page is set to noindex.
 * 
 * @param bool    $should_index
 * @param WP_Post $post
 *
 * @return bool
 */
if ( class_exists( 'WPSEO_Meta' ) ) {

  function filter_post( $should_index, WP_Post $post ) {
	
	if ( false === $should_index ) {
      return false;
    }
	
    return get_post_meta($post->ID, '_yoast_wpseo_meta-robots-noindex', true) == 1 ? false : true;
	
  }

  // Hook into Algolia to manipulate the post that should be indexed.
  add_filter( 'algolia_should_index_searchable_post', 'filter_post', 10, 2 );
}

/** 
 * Do not include certain pages by IDs
 * Page is set to index
 *
 * keyword "Afghanistan" - page ID 2293, 2439, 2423, 2420, 2431, 2387, 2427
 * Keyword  "Sudan" - page ID 36738, 3934, 3936, 3932, 36772, 36778
 */
 
function exclude_post_ids( $should_index, WP_Post $post ){
	
    // Add all post ids to exclude
    $excluded_ids = array( 2293, 2439, 2423, 2420, 2431, 2387, 2427, 36738, 3934, 3936, 3932, 36772, 36778 );
	
	if ( false === $should_index ) {
      return false;
    }

	return ! in_array( $post->ID, $excluded_ids, true );
}

// Hook into Algolia to manipulate the post that should be indexed.
//add_filter( 'algolia_should_index_post', 'exclude_post_ids', 10, 2 );
add_filter( 'algolia_should_index_searchable_post', 'exclude_post_ids', 10, 2 );

Hey,

Could you try completely deleting your indices and start over?
Maybe it is because the pages didn’t get deleted.

Os yes it works now!

Thank you so much.