-
AuthorSearch Results
-
March 20, 2020 at 1:07 pm #237362
RossKeymasterHi Sigurd
After scratching my head I managed to figure out the issue.
We perform our search outside of the regular
WP_Query
, so if you choose a category in our search form, WP doesn’t actually “know” its restrciting to a specific category, because our search does that, so WP appends the stick post…I’ve managed to come up with some code, that add the WP category to the
WP_Query
(even though our plugin has already restricted the posts to this category), but now WP also knows that at a category restriction is happening, and excludes the sticky:add_filter("sf_edit_query_args", "add_wp_category_to_query", 100, 2); function add_wp_category_to_query($query_args, $sfid){ //if($sfid == 1234){ //you can restrict this behaviour to a search form ID //get user category selection from the search form (ie, detect which categories have been selected) global $searchandfilter; $query_data = $searchandfilter->get($sfid)->current_query(); $query_data_array = $query_data->get_array(); if(isset($query_data_array['_sft_category'])){ $category_values = $query_data_array['_sft_category']['active_terms']; $current_category_ids = array(); //this will contain all the IDs of the categories that have been selected in the search form foreach($category_values as $category){ array_push($current_category_ids, $category['id']); } //restrict query to WP category $query_args['category__in'] = $current_category_ids; } //} return $query_args; }
As there may be some small overhead when implementing this code, you can uncomment the first
if(
line, and restrict this to a specific search form / query.I hope that makes sense & works!
Best
March 19, 2020 at 4:26 pm #237221
TrevorParticipantYou seem to have customised the results.php file, but it must have errors as it also shows ‘no results found’?
This post might help you with code for what you want:
That code is for _sft_category and the id number is wrong, so maybe this?
global $searchandfilter; $sf_current_query = $searchandfilter->get(3637)->current_query(); $sf_current_query_array = $searchandfilter->get(3637)->current_query()->get_array(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>No category selected.</div>'; } else { echo '<div>' . $sf_current_query_array["_sft_menucats"]["active_terms"][0]["value"] . '</div>'; echo '<div>' . $sf_current_query_array["_sft_menucats"]["active_terms"][0]["id"]. '</div>'; echo '<div>' . category_description($sf_current_query_array["_sft_menucats"]["active_terms"][0]["id"]). '</div>'; }
Otherwise, are you able to send me temporary WordPress admin logins (ones you should later delete or disable) for the site so that I can look at the setup? Please use a Private Reply.
March 17, 2020 at 3:16 pm #236976In reply to: Range Slider is getting triggered by default
AnonymousInactiveI tried to unset the slider using
sf_edit_query_args
, but it doesn’t clear the search results. It still keeps the slider query!This is what I have tried:
function filter_function_name( $query_args, $sfid ) { global $searchandfilter; $current_query = $searchandfilter->get(58376)->current_query()->get_array(); unset( $current_query['_sfm_LENGTH_KEY'] ); return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
But it doesn’t do anything! Posts are still being filtered with the slider query!
March 11, 2020 at 11:35 am #236248In reply to: Category description in search results
TrevorParticipantI added this code:
https://www.screencast.com/t/WYIjHhwBYb
This:
global $searchandfilter; $sf_current_query = $searchandfilter->get(332)->current_query(); $sf_current_query_array = $searchandfilter->get(332)->current_query()->get_array(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>No category selected.</div>'; } else { echo '<div>' . $sf_current_query_array["_sft_category"]["active_terms"][0]["value"] . '</div>'; echo '<div>' . $sf_current_query_array["_sft_category"]["active_terms"][0]["id"]. '</div>'; echo '<div>' . category_description($sf_current_query_array["_sft_category"]["active_terms"][0]["id"]). '</div>'; }
February 24, 2020 at 1:47 pm #234731
AnonymousInactiveLike this?
<?php //grab the active query from our search form //replace <code>1526</code> with the ID of your search form global $searchandfilter; $sf_current_query = $searchandfilter->get(3969)->current_query(); ?>
February 24, 2020 at 1:30 pm #234724
TrevorParticipantI assume the $sf_current_query is defined before that line?
February 21, 2020 at 9:24 am #234544
TrevorParticipantDo you prefer the page to be empty, or maybe a message?
It looks like you are using the Shortcode display results method, in which case you should follow the ‘guide to customising’:
Once you have a copy of the results.php file in a
search-filter
sub-folder of your theme, you can edit that file, like this (leave the PHP comments at the top outside and before this code):global $searchandfilter; $sf_current_query = $searchandfilter->get(3204)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>Nothing to see here folks!</div>'; } else { // the current resuts.php code here }
February 17, 2020 at 5:12 pm #234134In reply to: Search Term not showing on Custom Archive Page
TrevorParticipantSo, that would be:
echo $sf_current_query["_sfm_city"]["active_terms"][0]["value"];
I think.
February 17, 2020 at 5:01 pm #234128In reply to: Search Term not showing on Custom Archive Page
AnonymousInactiveIt really doesn’t give me anything different then what i see above.
It shows what I queried but I simply need to display the Name of the City…when i attempt to use the first query i showed above to show _sfm_city it doesn’t display anything. How do i get the name of the city to display:
[_sfm_city] => Array ( [name] => [singular_name] => [all_items_label] => [type] => post_meta [active_terms] => Array ( [0] => Array ( [name] => Caracas [value] => Caracas ) ) ) )
<?php //Get a single fields values using labels //replace <code>1526</code> with the ID of your search form global $searchandfilter; $sf_current_query = $searchandfilter->get(1902)->current_query(); echo $sf_current_query->get_field_string("_sft_city"); ?>
February 17, 2020 at 4:45 pm #234116In reply to: Search Term not showing on Custom Archive Page
TrevorParticipantIf you use this code you would get the whole array:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1902)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>
Then you can see what each is called and contains.
-
AuthorSearch Results