Forums › Forums › Search & Filter Pro › Post Meta filter clears itself whenever an option is chosen.
- This topic has 20 replies, 3 voices, and was last updated 9 years, 4 months ago by
Ross.
-
Anonymous(Private) November 4, 2016 at 1:55 am #68521
After some digging, I have found that the issue is partially caused by the field names.
A field with the name
_sfm_details.genderwill be converted to_sfm_details_genderwhen the js makes the GET request. There’s code in place (in Search_Filter_Cache.init_filters) to handle when spaces get converted to underscores, but not when full stops do:$filter_name_get = str_replace(" ", "_", $filter_name);. Which causes the check to fail at this point:if(isset($_GET[$filter_name_get])).Adding a line to convert the full stop to an underscore seems to have fixed the filtering portion of this problem; but when it comes to displaying the fields, the selected option is not getting given the “selected” attribute. Looking at the function for determining whether a field is selected or not (in Search_Filter_Generate_Input):
`
private function is_option_selected($option, $defaults)
{
…
if(isset($option->selected_value))
…
}
`I cannot seem to find where selected_value is set. After doing a grep of all the files in the plugin, it doesn’t seem to be set anywhere obvious.
Because there is no selected value set, this causes the field to revert back to being empty.
My apologies if this post is an unorganized mess, but I hope what I have found is useful in some way.
Ross Moderator(Private) November 4, 2016 at 9:42 am #68555Thanks for the update, I didn’t realise
.get converted to_when part of a url param name :/Very strange but thanks for digging – as Trevor mentioned I’m just putting the finishing touches to an update, I’ll take a look at this over the weekend and if a modification needs to be made to S&F I’ll do that.
After which we can move on to the selected issue, I suspect that it is the same issue, as the Active Query class (which is used for the fields themselves) also uses
$_GETto grab the values, so I suspect its the conversion happening again.Best
Anonymous(Private) November 8, 2016 at 12:37 am #69137Hi Ross,
After doing a bit more digging, what you said is correct.
Adding the following fixes the issue.
public/includes/class-search-filter-active-query.php
after line 177
$field_name_get = str_replace(".", "_", $field_name_get); // do the same with full stopsafter line 596 (now 697 because of the above)
$sf_post_meta_key_get = str_replace(".", "_", $sf_post_meta_key_get); // do the same with full stops
public/includes/class-search-search-filter-cache.php
after line 150
$filter_name_get = str_replace(".", "_", $filter_name_get); // do the same with full stopsTested and working now.
Cheers,
Jayme
-
AuthorPosts