Comma separated list of custom taxonomy names

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Comma separated list of custom taxonomy names

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 4 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #45757
    tylerbartlett
    tylerbartlett
    Participant

    Hello, I am trying to include a list of terms in my search dropdown results. This is for a recipe blog. The recipe ingredients are setup in an ACF repeater field with 2 subfields for amount and ingredient name. The ingredient name type is a taxonomy so it can be searched globally for other recipes that share that ingredient. I would like to list the ingredient names in a comma separated list in the search results.

    The farthest I have gotten using the {} shortcakes returns the taxonomy ID but not the actual text.

    #45763
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Generally repeaters are very problematic to display as they are rendered differently for each case.

    Are the ingredient names by any chance actually assigned to the recipe? In that case using the {__tax_ingredient_name} (replace ingredient_name to the actual ingredient name taxonomy) could work.

    Best,
    Ernest Marcinko

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


    #45768
    tylerbartlett
    tylerbartlett
    Participant

    Thanks for the response, unfortunately this did not work. Can you think of any other possible work arounds? The ingredients are assigned to the recipe custom post type and I am able to use them elsewhere on the site such as in blog roll templates.

    One way I was able to work around this as an experiment was to concatenate the values of custom fields into a string of text that gets input into another custom field, assigned to the search description. That is to say, the field “recipe author” and “year published” are combined into a string, then when the post is published/updated, that the script runs and inputs the text into a summary field which is referenced in the search dropdown.

    Unfortunately, I am not a PHP programmer and was only able to achieve this through a lot of good luck and searching. I have attempted to modify the code to work for the repeater field but I have not had any luck. It seems like this would work but I don’t know enough about it to say for sure.

    I appreciate any insight you may be able to provide. Here is the code that is currently working as described above.

    Attachments:
    You must be logged in to view attached files.
    #45778
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Okay, I see how this works now. Without coding this is not possible, but it should not be too difficult whatsoever.
    Your code looks surprisingly perfectly fine to me, very good job – but I might be able to suggest a way based on that so you don’t have to use an additional field.

    Instead of that code, try this:

    add_filter( 'asp_results', 'asp_add_extra_field_data', 10, 1 );
    function asp_add_extra_field_data( $results ) {
      foreach ($results as $k=>&$r) {
    	  $slug = $r->post_type;
    	  $taxname = get_field('published_year', $r->id)->name;
    	  $origin = get_field('originator', $r->id)->name;
    	  $enjoyed = get_field('date_enjoyed', $r->id);
    	  $tipwrit = get_field('writer', $r->id)->name;
    	  $enjoydat = get_field('enjoyed_at', $r->id)[0]->post_title;
    	  $tippub = get_field('publication', $r->id)->name;
    	  
    	  $strung = $slug . ": " . $taxname . $enjoyed . $tipwrit . ', ' . $origin . $enjoydat . $tippub
      } 
      return $results;
    }

    Please be very careful and have backups! I may have made typos, as I am not able to test this.

    PS: Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    Best,
    Ernest Marcinko

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


    #45794
    tylerbartlett
    tylerbartlett
    Participant

    Thank you very much for the response and code snippet. I wasn’t able to get this to work but I was able to extend the functionality of my previous technique and it’s working really great now. Very awesome product, thanks again!

    #45795
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    All right, you are very welcome 🙂

    If you don’t mind, I will close this topic soon and mark it as resolved, feel free to open another one if you have other questions or issues.

    If you like the plugin and have not rated already, feel free to leave a rating on your codecanyon downloads page and on the wordpress plugin repository, it’s greatly appreciated.

    Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.