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

#56601
milena_u6jmmilena_u6jm
Participant

Thanks Ernest for your help!

I have added the following code but its not getting the desired results.

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 ( !empty($available) && $available !== '0' && $available !== 0 ) {
        return $post;
    }
    
    return null;
}, 10, 1);

When I run the logic to just list results, I get 717 items, which seems right. But when I delete and re-index, its only return 74 items.

Anything we can try here? I’ve add some login info to the ticket if that helps.

Let me know, thanks.

Seamus