Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Comma separated list of custom taxonomy names
- This topic has 5 replies, 2 voices, and was last updated 2 years, 7 months ago by
Ernest Marcinko.
-
AuthorPosts
-
October 19, 2023 at 1:11 am #45757
tylerbartlett
ParticipantHello, 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.
October 19, 2023 at 10:26 am #45763Ernest Marcinko
KeymasterHi,
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.October 19, 2023 at 4:05 pm #45768tylerbartlett
ParticipantThanks 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.
October 20, 2023 at 4:22 pm #45778Ernest Marcinko
KeymasterOkay, 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.
October 23, 2023 at 8:17 pm #45794tylerbartlett
ParticipantThank 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!
October 24, 2023 at 8:58 am #45795Ernest Marcinko
KeymasterAll 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.
-
AuthorPosts
- You must be logged in to reply to this topic.