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

Reply To: Setting up pre-filters for an index

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Setting up pre-filters for an index Reply To: Setting up pre-filters for an index

#56793
Ernest MarcinkoErnest Marcinko
Keymaster

I have very good news, I managed to find a solution, which hooks into the query to check the field existence and value. Use this snippet only:

add_filter(
	'asp/index/database/get_posts_to_index/query/add_where',
	function ( $add_where ) {
		global $wpdb;
		return $add_where . " AND ( 
		 ( post.post_type='attachment' AND EXISTS(SELECT 1 FROM $wpdb->postmeta WHERE post_id=post.ID AND meta_key='available' AND meta_value=1) )
		 OR post.post_type <> 'attachment'
		)";
	}
);

This will exclude everything during the query, so the exclusion field is not populated with so many items, they don’t even get queued at all.