heimer16
Forum Replies Created
-
Forum: Plugins
In reply to: [Ultimate WP Query Search Filter] type being echoed to screenI understand that getting no subcategories may be a bit of an edge case, but you say it won’t affect much because it already returns for each of the types, but in the case that $count = 0, it does not. Also, I cannot “always use the filter hook” (uwpqsf_tax_field_checkbox), because again, where $count = 0, it never gets called.
We could go on, but in the end it’s an edge case and a combination of things that result in “checkbox” getting output to the screen. I’ll post my work-around below just in case someone else finds themselves in a similar situation and may find it useful.
add_filter('uwpqsf_addtax_field_checkbox', 'uwpqsf_type_output_fix'); add_filter('uwpqsf_addtax_field_radio', 'uwpqsf_type_output_fix'); add_filter('uwpqsf_addtax_field_dropdown', 'uwpqsf_type_output_fix'); function uwpqsf_type_output_fix($html) { if (in_array($html, ['dropdown', 'checkbox', 'radio'])) return ''; return $html; }
Forum: Plugins
In reply to: [Ultimate WP Query Search Filter] type being echoed to screenHi, thanks for your reply. I appreciate your time looking into this.
I’m not suggesting removing the $count > 0. I understand why that’s there. But you say it is pointless to add the filter if there are no terms, but I would argue if I wanted to output something like “No subcategories found”, I could not because the filter would not run. But that is only a small point.
The main issue is that having empty subcategories should return nothing. But it does not. It returns the string “checkbox”
And the “or” statement actually does have a lot to do with my issue here. I understand why that custom filter is there. But what I’m saying is that if($type != ‘dropdown’ or $type != ‘checkbox’ or $type != ‘radio’) ALWAYS RETURNS TRUE. So in my case, $count = 0, none of the above return statements fire, so it arrives to this if statement and since again, please check the logic, it ALWAYS RETURNS TRUE, it returns the custom field filter even though my $type = ‘checkbox’.
that by itself is not the whole issue
I think the bigger issue is that in the custom field filter, apply_filter is missing $html as the 2nd parameter. There are only 12 parameters when the others have 13. The others have $type as the 3rd parameter but here $type as the 2nd parameter, which again, is my case is ‘checkbox’ and that is why the word “checkbox” is output to the screen when there are no subcategories.
I hope I am explaining myself well. Thanks again.
Forum: Plugins
In reply to: [Ultimate WP Query Search Filter] type being echoed to screenHi, thanks for the reply,
Maybe it will help to explain a little further. I’m showing this filter box on category pages, and I’m adding a filter (on uwpqsf_taxonomy_arg) to only show subcategories of the current category. So for example I’m adding “parent” => [100] to $args.
On category pages that have subcategories, it works fine. But some categories do not have subcategories, so on those pages, the word “checkbox” gets output to the screen.
Problem 1 is that in the output_formtaxo_fields function, if get_terms returns an empty array (and $type = ‘checkbox’) it doesn’t pass the $count > 0 check so it does not return actually continues and returns the custom addtax filter at the bottom of the method.
One solution would be to pull the return apply_filters outside of the $count > 0 if block and it would solve this issue.
Problem 2 is that if you count the # of parameters in the checkbox filter, there are 13 parameters and $type is the 3rd parameter:
return apply_filters( 'uwpqsf_tax_field_checkbox', $html ,$type,$exc,$hide,$taxname,$taxlabel,$taxall,$opt,$c,$defaultclass,$formid,$divclass);
but if you look at the custom field filter, there are only 12 parameters and $type is the 2nd parameter.
return apply_filters( 'uwpqsf_addtax_field_'.$type.'', $type,$exc,$hide,$taxname,$taxlabel,$taxall,$opt,$c,$defaultclass,$formid,$divclass);
and in the wordpress documentation for the apply_filters function, the 2nd parameter gets returned and output to the screen, so in my case, if there are no subcategories, and $type = ‘checkbox’, the custom filter runs, passing $type as the second parameter which is why I’m getting “checkbox” on the screen.
Also, my point about the “or” statement is that it’s exactly the same as writing if(true) so it will always run, and I’m not sure that’s what you intend.
$types = ['dropdown', 'checkbox', 'radio', 'custom']; foreach ($types as $type) { if($type != 'dropdown' or $type != 'checkbox' or $type != 'radio') { echo 'true'; } }
this will return truetruetruetrue