• Resolved bigmoose

    (@bigmoose)


    I have a site with a lot of content and we have hit our limit, we don’t want it to be indexed if its older than say 1-2 years, i tried this code but got a critical error.

    function wpswa_support_should_index_post( $should_index, $post ) {
    	global $post;
    	
    	// Check if post date or modified date is older than 2 years, if yes, return false to prevent indexing.
    	if (strtotime($post->post_date) < strtotime('-1 year') && strtorime($post->post_modified) < strtotime('-1 year')){
    		return false;
    	}
    
    	// Otherwise return our original value
    	return $should_index;
    }
    add_filter( 'algolia_should_index_post', 'wpswa_support_should_index_post', 10, 2 );
    add_filter( 'algolia_should_index_searchable_post', 'wpswa_support_should_index_post', 10, 2 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Couple quick thoughts, since we’re passing in the $post object that the indexing is considering, no need to do global $post

    Second thing is that you have a typo with strtorime in your post modified check.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Also, if you’re on the free tier with this, where the cap is at 10k records, a couple weeks back or so they made some new announcements where the “Build Plan” offers up to 1 million records.

    You can read more about that announcement at the end of https://www.algolia.com/blog/engineering/devbit-1-recap/

    Only “downside” is you’d need to create the application fresh, no way to upgrade your current one, so a migration plan would need to be made.

    Thread Starter bigmoose

    (@bigmoose)

    Well this is super embarrassing, missed that typo and all is working

    I’ve checked out the Build plan and will migrate to that as well, thank you!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Glad I could help.

    Let us know if you need anything else.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Exclude older content by date’ is closed to new replies.