Images in search results – sources

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Images in search results – sources

This topic contains 4 replies, has 2 voices, and was last updated by nazar nazar 7 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9063
    nazar
    nazar
    Participant

    Hello,

    First off, thanks for this amazing plugin. It’s the best one I’ve worked with so far!

    I have a suggestion regarding images in search results – actually, about image source options.
    Currently we have ‘generic’ options only (featured image, etc). Obviously, these will only work for posts and CPTs – e.g. there’s nothing applicable to taxonomies.

    In my case I have configured a combination of search sources that include CPTs, custom taxonomies and custom fields of CPTs.
    It would help a lot if there was a possibility to set images for search results per every search source.
    For example, I could set ‘featured image’ for posts, standard/default image (or term meta field) for taxonomy, another standard/default image for a different taxonomy, etc.

    A decent example of what would be cool to be able to do is https://www.daysoutwithkids.com/
    Try typing ‘lo’ – you’ll see a list of suggestions. Different types of search results (locations and attractions) have different icons.

    Maybe I’m missing something and a similar thing is already possible with Ajax Search Pro?
    Or maybe I can achieve this with some custom code snippets? 😉 Any tips of guidance will be highly appreciated.

    Thanks again.

    #9068
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    While it is a great idea, the problem is that taxonomy terms have no images by default in WordPress (as far as I know). So there is no standard way of parsing those images, it varies for every plugin. This fact makes it impossible to implement a feature to select image sources by taxonomy.

    I can of course suggest a way to display the term images, but I need to know how they are stored, or how to get them.

    For example, I have found different poast support topics for this, and each one has a different resolution based on how the taxonomy term images are stored:

    Term images using PODS
    Term images using woocommerce term meta
    Term images using Featured Images for categories plugin
    Another different storage method

    This is only the ones I could find in a few minutes, there is much more. As you can see, each and every solution is different, depending on the implementation.

    Do you know by any chance how those images are added to the taxonomies? (any plugin used, or a theme method or something else)
    If you happen to know the function name to use to get the term images by ID, that would be the jackpot.

    Best,
    Ernest Marcinko

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


    #9071
    nazar
    nazar
    Participant

    Hiya Ernest,

    I believe, the most ‘standard’ way is the native term meta: https://www.smashingmagazine.com/2015/12/how-to-use-term-meta-data-in-wordpress/
    I usually use either that (yep, coding everything manually) or Pods (when my customers need a GUI).

    I checked your code snippets in those threads and I can see different approach depending on plugins/functions used, however, I’m kinda stuck with writing a proper filter for my case.
    In my current setup I have the following combination of search sources: 1 CPT, 2 custom taxonomies, 1 custom field.
    In plain English: Listing (CPT), Listing Category and Listing Region (hierarchical taxonomies), zip code (CPT custom field).

    Now, search results will display thumbnails for listings (CPT match), taxonomy name (taxonomy match), and thumbnails for listings again (custom field match).
    So can I ‘assign’ default search results images for those taxonomies? I prefer a simple static image for each taxonomy for now.
    Almost like https://www.daysoutwithkids.com/ do that, if we assume that attraction and location are taxonomies.

    And just in case you know the answer 🙂
    I might add images and other term meta to taxonomies using Pods – e.g. flag icons and state abbreviations for Regions, some icons for Categories, etc.
    Do you know how to make these appear in search results? E.g. a flag icon near country name, state abbreviation after state name, etc?

    Also, while I’m here…
    Chances are we’ll be adding another CPT – Celebrities, so we’ll end up with two CPTs in search sources.
    In that case we’ll want to display a standard image in search results for every CPT (exactly like https://www.daysoutwithkids.com/ if we assume that attraction and location are CPTs).
    Is there a neat way to do this?

    Thanks!

    #9098
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Yeah, term meta is great, but unfortunately devs are not using it yet. I was hoping advanced custom fields plugin will switch first, but last time I checked, it is still using a different method storing term meta (in the options table).

    I see you have lots of different cases, so here is a very generic filter code I put together, which helps you distinguish different result types:

    This should answer all your questions and should cover all possible cases.

    Best,
    Ernest Marcinko

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


    #9101
    nazar
    nazar
    Participant

    Hiya Ernest,

    Wow, thanks for that!
    Now I can also see what I was doing wrong in my code 🙂

    Yeah, ACF and their wp_options approach…
    That’s the only reason I don’t use ACF. You’re right, they didn’t switch to term meta yet, not sure if it’s on their roadmap either.
    People do request the switch – https://support.advancedcustomfields.com/forums/topic/how-to-use-wp-term-meta-on-acf-the-easy-way/ – but I’m guessing they have to either maintain backwards compatibility or build a migration routine (or even both). None of those is a trivial task…

    Thanks again for your help.

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

The topic ‘Images in search results – sources’ is closed to new replies.