Image source settings

This topic contains 4 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 4 years, 11 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #22852
    DSLMS
    DSLMS
    Participant

    Hello, I have an issue with the result image settings.

    In Alternative image source 3 I have a custom field selected. This works fine with my custom image.
    In Alternative image source 4I have the default image selected.

    The problem is that when source 4 is set, it gets priority over source 3 somehow and shows instead!
    If I disable source 4 then it shows the custom image correctly. When I turn source 4 back on the result then shows from source 4 instead of source 3.

    I’ve attached screenshots in two zip files that i’ve attached show what I mean if I haven’t explained it well.

    Any ideas why this is happening please?

    Attachments:
    You must be logged in to view attached files.
    #22855
    DSLMS
    DSLMS
    Participant
    You cannot access this content.
    #22864
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    The issue is related to a custom code you have to get the taxonomy images within your theme functions.php file. Since the plugin does not find the image internally, it uses the default image. Then the custom code is executed, but since there is already an image, it is not in use. Try replacing it with this variation instead:

    add_filter( "asp_results", "asp_acf_cf_image", 10, 1 ); 
    function asp_acf_cf_image( $results ) {
        // Change this to the ACF custom field name
        $image_field = 'search_image';
        $default = 'https://domain.com/wp-content/plugins/ajax-search-pro/img/default.jpg';
        
        // ----------------------------------------------
        // --- Do not change anything below this line ---
        // ----------------------------------------------
        foreach ( $results as $k => &$r ) {
          if ( ( empty($r->image) || $r->image == $default ) && $r->content_type == 'term' ) {
            $img = get_field($image_field, $r->taxonomy . '_'.$r->id);
            if ( !empty($img) )
              $r->image = str_replace("'", "%27", $img);
          }
        }
        return $results;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #22933
    DSLMS
    DSLMS
    Participant
    You cannot access this content.
    #22934
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.