Forums › Forums › Search & Filter Pro › "Showing results under X and Y and Z"
- This topic has 9 replies, 2 voices, and was last updated 9 years, 5 months ago by Ross.
-
Anonymous(Private) April 7, 2015 at 6:04 pm #14685
Hello,
Just a quick question on where to get started to display a heading sentence before displaying the results, inside search.php, so that it states something like_
Displaying results under CATEGORY-1 and META-1 and TAG-1
Should I parse the url, then get the category slug, then query to get the category name?
Ross Moderator(Private) April 7, 2015 at 6:25 pm #14688Hey Marc
You’ve got the right idea.
Depends on where you are needing to do it, but you could check the
$wp_query->query
object, which will have those vars from the URL.Just to note, S&F adds a prefix of
_sft_
to taxonomies and_sfm_
for meta fields which you may need to strip before processing.Here is a similar post where I’ve written a function for parsing taxonomies to get you started:
https://support.searchandfilter.com/forums/topic/how-to-show-cats-title-in-search-result/
๐
Anonymous(Private) April 13, 2015 at 10:55 am #14966Hi Ross,
Thank you, you showed me the light ๐
Here is my approach (I am using the Advanced Custom Fields plugin for meta values):<?php $copy = array(); $is_search = false; $search_query = $wp_query->query; // META if($search_query['_sfm_location']){ $field = get_field_object('location', false, array('load_value' => false)); foreach ($field['choices'] as $key => $value) { if($key == $search_query['_sfm_location']){ $copy[] = $value; } } $is_search = true; } // TAXONOMY if($search_query['_sft_project_category']){ $term = get_term_by('slug', $search_query['_sft_project_category'], 'project_category'); $copy[] = $term->name; $is_search = true; } ?> <?php if($is_search): ?> <p>Searching filters for: <?php echo implode(', ', $copy); ?></p> <?php else: ?> <p>A simple copy when if no search.</p> <?php endif; ?>
Ross Moderator(Private) April 13, 2015 at 7:57 pm #15004Thanks for that!
Does that grab the names of the values from ACF automatically?
Anonymous(Private) April 14, 2015 at 8:14 am #15035Yes!
get_fields() and get_field_object() does grab all custom fields info
http://www.advancedcustomfields.com/resources/get_fields/Ross Moderator(Private) April 14, 2015 at 8:19 am #15036Ohhh lovely! Hadn’t got round to checking ACF functions yet but they’ll help with grabbing the names automatically in some updates I’m working on ๐
Ross Moderator(Private) July 21, 2015 at 4:45 pm #21816Hey Marc,
Not sure I follow, the code you placed above is what I think you mean, but then that must mean I’m getting confused…!
If you can please elaborate a little more? ๐
Thanks
Anonymous(Private) July 21, 2015 at 5:22 pm #21823Sorry, i was too straightforward. I put it another way:
Imagine I create a new form. Create a new field, type Post Meta. Then i choose to Display my Meta Field with a dropdown, which I manually fill it some options:
value_1, label_1, .... value_n, label_n
. Done.Whan I submit the form and go to a new page, i will e able to retrieve the
value_n
via wp_query, but then how can I get the correspondinglabel_n
Thank you!
Ross Moderator(Private) July 27, 2015 at 10:57 pm #22167Hey Marc
I thought thats what you were explaining all the way at the top.
S&F doesn’t have a way to get this info, for example, if it was a taxonomy you would use – https://codex.wordpress.org/Function_Reference/get_term_by against the value.
I just did a quick google and found this:
http://wordpress.stackexchange.com/a/140825/37783 – check step 3 of this answer RE label – I guess this is an ACF question really.
Thanks
-
AuthorPosts