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
January 5, 2026 at 1:22 pm
#56675
Participant
Hey Ernest,
Hope you had a good break!
So back on this now, here is my current snippet:
add_filter('asp_index_post', function( $post ) {
if ( $post === null ) {
return $post;
}
// Only apply this filter to attachments (media)
if ( $post->post_type !== 'attachment' ) {
return $post;
}
$meta_key = 'available';
if ( function_exists('get_field') ) {
$available = get_field( $meta_key, $post->ID, false ); // ACF support
} else {
$available = get_post_meta( $post->ID, $meta_key, true );
}
// Check if the field exists and is truthy (1, "1", true, "yes", etc.)
if ($available === true || $available == '1') {
return $post;
}
return null;
}, 10, 1);
But its only returning 25 results. When re-creating the index, it also seems to run slowly, then go from like 10% to completed instantly, which feels a bit out, like its getting stopped?
When I run this logic against the database in a script, I get 370 results, which is the correct amount of results:
if ($total_media > 0) {
foreach ($media_ids as $id) {
/**
* 2. Check the ACF field 'available'.
* ACF usually stores booleans as '1' (true) and '0' (false) in the DB.
* get_field() handles the logic correctly.
*/
$is_available = get_field('available', $id);
if ($is_available === true || $is_available == '1') {
$available_count++;
} else {
$unavailable_count++;
}
}
}
So I think the available logic is right, but something else is happening?
Let me know, thanks.