This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Exclude Pages and Child-Pages from Search Index

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Exclude Pages and Child-Pages from Search Index

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #48214

    Is it possible to exclude all posts with a relative path “/path/to/excluded/posts/*” with a wildcard, i.e. exclude all children of “”/path/to/excluded/posts/” from being used for building the search index?

    Kind regards

    Thomas

    #48221
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi Thomas,

    If the pages are in a parent-child relationship directly, then you can exclude them.

    For pages there is going to be a checkbox to exclude direct children as well. However this will not exclude them from the index, but only from the individual search instance.

    You can however do it programmatically, so before a post is indexed a check is executed to exclude it from the index, something like this:

    add_filter(
    	'asp_index_post',
    	function ( WP_Post $post ) {
    		if ( strpos($post->guid, '/path/to/excluded/posts/') !== false ) {
    			return null;
    		}
    		return $post;
    	}
    );

    Please note that I did not test this code, but it should be very close to a solution.

    Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    #48224

    Hi Ernest,

    thanks a lot for your fast response!

    Kind regards

    Thomas

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.