• Resolved panmaster

    (@panmaster)


    Hi,

    I moved to the SEO Framework but I am struggling to make it work with SearchWP plugin.

    Basically I’d like to exclude all the noindex pages that have a certain tag.

    This below is the code I use for Yoast SEO. Could you please help me to adapt it to SEO Framework?

    function my_searchwp_wordpress_seo_exclude_noindex( $ids, $engine, $terms ) {
    	$entries_to_exclude = get_posts(
    		array(
    			'post_type'  => 'any',
    			'nopaging'   => true,
    			'fields'     => 'ids',
    			'meta_query' => array(
    				array(
    					'key'      => '_yoast_wpseo_meta-robots-noindex',
    					'value'    => true,
    				),
    			),
    		)
    	);
    	$ids = array_unique( array_merge( $ids, array_map( 'absint', $entries_to_exclude ) ) );
    	return $ids;
    }
    add_filter( 'searchwp_exclude', 'my_searchwp_wordpress_seo_exclude_noindex', 10, 3 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    I think you should change the key from _yoast_wpseo_meta-robots-noindex to _genesis_noindex, and the value from true to 1.

    Please note that the query doesn’t consider the inversion options (force index is -1, default is 0, and force noindex is 1), nor the global robots’ post-type settings.

    To work around that, you’ll need to implement something in the filter proposed that’s so heavy it’ll crash your website… Therefore, another hook needs to be used, but I can’t find the source of SearchWP. You may want to reach out to the authors (Pagely?) and tell them you need to implement a loop on the search results (after the SQL query is finished) that uses this method:

    the_seo_framework()->is_robots_meta_noindex_set_by_args( [ 'id' => $post_id ], \The_SEO_Framework\ROBOTS_IGNORE_PROTECTION )
    

    However, we already thought ahead on that, and we included per-post search-exclusion options with The SEO Framework, which should also affect SearchWP. It’s much more performant than the slow get_posts() query used in the example posted above.

    The SEO Framework exclude post from search

    I hope these insights help ?? You can get started with the changes I mentioned in the first paragraph of this reply. But when your site grows (too) large, or when you use the robots inversion options, you may find the workarounds suit better. Cheers!

    Thread Starter panmaster

    (@panmaster)

    Hi Sybre

    Many thanks for your reply.
    Really appreciated the new way to exclude the pages from the queries!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to exclude SEO Framework noindex pagess’ is closed to new replies.