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

Forum Replies Created

Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • in reply to: Setting up pre-filters for an index #56706
    milena_u6jmmilena_u6jm
    Participant

    Ahhhh, think I found something…

    Would it have to do with the fact most of my media library is WebP images?? How can I add these as an allowed mime type?

    I ran a report off the index and noticed the 25 are all jpgs, no one WebP was in there. Then I checked my available works list, only 25 are JPG, the rest are WebP.

    WebP is an accepted WordPress MIME type, but I’m guessing we need to get a code tweak to get it into ASP?

    Let me know, thanks Ernest!

    • This reply was modified 6 months, 2 weeks ago by milena_u6jmmilena_u6jm.
    in reply to: Setting up pre-filters for an index #56700
    milena_u6jmmilena_u6jm
    Participant

    Yeah, does seem to be kinda working, but not all the way we would like!

    I’ve just re-added the user details from the private part of this post, the custom code is in a snippet called “ASP – Pre index filter to only grab available works”

    Thanks Ernest!

    in reply to: Setting up pre-filters for an index #56683
    milena_u6jmmilena_u6jm
    Participant

    OK, so have attached two lists for you, one is the data from the ignore list, and the other is a report with the available media ids. These look ok, the avialables are newer ids, and the ingores are all older.

    But there’s one thing that looks wrong… The ignore list is only 1153 entries. There are 7700 media items, and with only 370 avialables, shouldnt the ignore list be closer to 7300?

    I deleted the ignore list, and rebuild the index, comes back with the same amount again.

    in reply to: Setting up pre-filters for an index #56675
    milena_u6jmmilena_u6jm
    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.

    in reply to: JS function to re-sort the results #56631
    milena_u6jmmilena_u6jm
    Participant

    Thanks my friend, that one is resolved by adding those two fixes. Love your work!

    in 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

Viewing 6 posts - 16 through 21 (of 21 total)