Forums › Forums › Search & Filter Pro › How to show cats title in search result?
- This topic has 14 replies, 6 voices, and was last updated 9 years, 2 months ago by Ross.
-
Anonymous(Private) January 26, 2015 at 10:32 am #10925
The following shows the term i search as a title title if I use the search field but if I select a category from the drop down, the results are fine, the number of results displayed in the title are fine but i get an empty title:
<h1 class="search-title"> <?php echo $wp_query->found_posts; ?> <?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>" </h1>
Becomes:
6 Search Results Found For: ""
Where between For: “..” there should be the category or categories and the search term if all have been used to make the search i suppose
Thanks
Ross Moderator(Private) March 18, 2015 at 11:37 pm #13652Hey Roberto
This must have slipped through – thanks Josef for reviving it.
To get your search term then please read the below:
If you are using the shortcode to display results, then you can use:
<?php echo esc_html($query->query['s']); ?>
When using the archive method and using a template from your theme,
<?php the_search_query(); ?>
Should be absolutely fine, however if this is not working for some reason, you could try:
<?php echo esc_html($wp_query->query['s']); ?>
Also, remember to check that
['s']
is set before using it.Josef, I’ve noticed your other ticket too, about extracting the rest of the search info such as taxonomy terms etc – I’ll follow up shortly with a post about that.
Thanks
Ross Moderator(Private) March 18, 2015 at 11:50 pm #13653Ok here is some sample code to retrieve the values for a specfic taxonomy:
function get_taxonomy_values($taxonomy_key) { global $wp_query; global $wpdb; if(isset($wp_query->query[$taxonomy_key])) { if (strpos(esc_attr($wp_query->query[$taxonomy_key]),',') !== false) { $ochar = ","; $taxterms = explode($ochar, esc_attr(($wp_query->query[$taxonomy_key]))); $taxlabels = array(); foreach ($taxterms as $taxterm) { $taxlabel = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE slug='".$taxterm."'"); array_push($taxlabels, $taxlabel); } return implode(" or ", $taxlabels); } else { $ochar = "+"; $taxterms = explode($ochar, esc_attr(urlencode($wp_query->query[$taxonomy_key]))); $taxlabels = array(); foreach ($taxterms as $taxterm) { $taxlabel = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE slug='".$taxterm."'"); array_push($taxlabels, $taxlabel); } return implode(" or ", $taxlabels); } } }
This is just something I’ve written myself, you’ll want to modify it to display how you want..
Then to display just do:
echo get_taxonomy_values("_sft_pa_size");
Where the taxonomy name is
pa_size
– if you use this plugin without Ajax, you will notice the URL update when you search, if in this example I had a taxonomypa_size
and submitted the form then you will see_sft_pa_size
in the URL, this is what you need to use to retrieve a specific taxonomy.Categories and tags are also treated as taxonomies, their names would be
_sft_category
and_sft_post_tag
respectively.Thanks
Ross Moderator(Private) March 19, 2015 at 1:38 pm #13709Which part is giving you a problem, the actual search terms a user can enter in a search box?
The example above should work fine:
<?php echo esc_html($query->query['s']); ?>
Just make sure its after
has_posts
Thanks
Ross Moderator(Private) March 21, 2015 at 11:41 pm #13791Hi Josef
If you are using ajax, and the text is not updating when you submit, then you must place the title in your results template – within the area that is getting loaded by ajax – same goes for your pagination.
Thanks
Anonymous(Private) March 22, 2015 at 9:30 am #13798Hi Ross,
I have tested number of places before replaying your answer, and even include it in the loop the search-filter folder.lets make sure that i did the process correct.
1. insert the code to the theme functions.php
2. include the “echo get taxonomy value” in the search-filter > id.php {when the id is the id of the search as in the shortcode number }Hope for your help
thanks in advance
Josef -
AuthorPosts