Forums › Forums › Search & Filter Pro › boolean custom field filtering not working
Tagged: custom fields
- This topic has 12 replies, 2 voices, and was last updated 9 years, 10 months ago by Ross.
-
Anonymous(Private) December 11, 2014 at 8:52 am #8912
Hi,
I’m a new customer of the pro version, and I can’t seem to get the post meta to filter correctly.
I have a boolean custom field in my post (from advanced custom field) that can either take on 0 or 1. I’ve set the value in my posts, and through printing out the value using confirmed that indeed, this value is printing out as 0 or 1.
When I try to filter on this value (using Post Meta), I observe some bizarre behavior.
It seems to be recognizing and filtering on the 1 value just fine, but it does not filter at all on the 0 value (it lets all the 1 values through too, even though I checked that my post does indeed have a 0 value for that custom field). In addition, when I set the search operator to OR, and I select both 0 and 1, it says “no results found”.
Thanks,
GregRoss Moderator(Private) December 11, 2014 at 1:30 pm #8923Hey there
Sorry for the generic message – I got locked out and blacklisted by my host for this website!! – so been unable to login and reply to tickets – playing catchup now – will be systematically working through tickets today.
Thanks
Anonymous(Private) December 12, 2014 at 5:23 am #8982Hi Ross,
I’ve spent some time gathering a bit more information that I hope might be helpful in finding the solution.
As I said above, I’m using the TRUE/FALSE field in Advanced Custom Fields. This assigns a key value of either 0 or 1.
I then create a Search and Filter Pro filter for it (post meta) that has two values : 0 or 1, each with its own label.
The “1” value works fine. It attaches a tag such as “?_sfm_key=1” to the url.
The “0” value, when selected in the form (i’m using a checkbox), does nothing to the URL.
*However*, when I manually enter “?_sfm_key=0” into the URL, the filter executes as expected.
So, somehow, it appears that the checkbox in the form is not attaching the proper query to the URL when the value is 0…is there perhaps a special case being handled for a 0 value?
Thanks,
GregRoss Moderator(Private) December 13, 2014 at 2:32 pm #9032Hey Greg
You’re absolutely spot on with that actually – for many fields such as taxonomy, I always manually add an option such as “All Categories” and I use the value of “0” to handle this easily.
I realise now, in your case with the Custom Fields that “0” really is not suitable any more and maybe some special processing going on to ignore that field.
Do you have a working link I could look at?
Thanks
Anonymous(Private) December 13, 2014 at 5:01 pm #9043Sure, thanks for your help! The link is here:
http://dev.graceatworkllc.com/calvary/sermons-archive/
THe category in question is the “sermons” and “sunday schools”. Sunday schools is mapped to 1 and works, sermons is mapped to false (0) and doesn’t work.
Unfortunately, in advanced custom fields, i dont’ think for the true/false type there’s way to map to any value other than 0 or 1…
just a suggestion, but would is_numeric be a good way to handle the “all catgories” case?
Upon reflection, I guess what I really want is for the boxes to be checked by default, and then people can uncheck to remove one category or another … is this possible too?
Thanks,
GregAnonymous(Private) December 16, 2014 at 4:19 pm #9132Hey Ross,
Just wondering if you had a chance to look into this issue?
Actually, I took back what I said at the end of the last email…I don’t need all the checkboxes checked by default…don’t know what I was thinking 🙂
But any idea how to get the 0 field to work for true/false types?
Thanks,
GregRoss Moderator(Private) December 16, 2014 at 10:31 pm #9162Hey again!
I’m going to have to make some modification to the plugin to fix the boolean support – once I’ve done that we can have a look at the rest – however there is currently no way to set defaults for the search form.
Thanks
Ross Moderator(Private) December 20, 2014 at 4:42 am #9313I’ve managed to fix this and will be available in next update (tomorrow providing testing goes well).. 🙂
-
AuthorPosts