Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Hide Posts with Boolean Custom Field On True
- This topic has 9 replies, 2 voices, and was last updated 4 years, 3 months ago by
Ernest Marcinko.
-
AuthorPosts
-
February 10, 2022 at 10:23 pm #36633
capstonedesign42
ParticipantHello. I am trying to filter items based on a custom field and can’t get it to work. I read your knowledge base without much luck. I have a Jobs custom post and within that there is a “true/false” advanced custom fields post type.
Within the Jobs entry I can enable the Deactivate Job Post (true/false) switch. Is there a way to prevent any Job post from displaying if the Deactivate Job Post custom field is set to Yes? (Yes is supposed to deactivate the post from showing in the search result listings and the post feed). We don’t want to draft the posts, we just want to turn on the Deactivate Job Post, which would hide the results.
I hope this makes sense and thank you for your help!
Michael
February 11, 2022 at 2:55 pm #36685Ernest Marcinko
KeymasterHi Michael,
I have no experience with boolean fields, but I assume they store the json_encoded value in the custom fields data table (as all custom field values have to be converted to strings).
In that case I would suggest trying this setup: https://i.imgur.com/VPpN3A2.png
The JSON encoded value of the boolean values includes the strings “true” and “false”, so that should match it.February 13, 2022 at 7:55 pm #36712capstonedesign42
ParticipantHello. Unfortunately, this didn’t work for me. Or perhaps I didn’t understand your screenshot. Do you have any way for me to hide any post that has a custom field set to True or Yes? I wan’t to hide it from the search results and also hide from displaying in the feed as well. Or do I need to write some function to hide it? I am not good at writing WP functions. Thank you!
February 14, 2022 at 2:28 pm #36720Ernest Marcinko
KeymasterIt is definitely possible if it is made via ACF. I checked the plugin source, and it appear that the field value for the “boolean” type is actually either 0 for true or 1 for false.
If you need an “invisible” filter to simply hide the jobs where this field is “false”, then you could do something like this: https://i.imgur.com/xpDsSdW.png
..and also, if you want to allow items, which does not have this field assigned, then turn on this option: https://i.imgur.com/lcPWyA6.pngFebruary 14, 2022 at 8:37 pm #36736capstonedesign42
ParticipantHi. Unfortunately, this solution does not work. Do you have any other recommendations?
February 15, 2022 at 1:04 pm #36742Ernest Marcinko
KeymasterIt should work, I am 99% positive. Do you want to hide the ones where the field value is true right?
I think what I suggested may work the opposite way. Can you try a different operator: https://i.imgur.com/r9xtODP.pngThat should allow items where the operator is not 1, or not set.
February 16, 2022 at 5:55 pm #36778capstonedesign42
ParticipantYou cannot access this content.
February 17, 2022 at 4:59 pm #36799Ernest Marcinko
KeymasterOh okay, I see what you need now.
The issue with that is, when you load up the page, the plugin will not do anything to the elementor widget, until it is loaded. You have basically two options to resolve that:
– Via Elementor – I believe there are query options for the posts widget, to exclude certain items, however I do not know if post meta based exclusions are supported.
– Or simply enable auto populate on ajax search pro, with this configuration: https://i.imgur.com/au3yNmK.pngThe second options might be easier in my honest opinion.
February 17, 2022 at 7:20 pm #36808capstonedesign42
ParticipantThat did it! Thank you!
February 17, 2022 at 8:38 pm #36811Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- You must be logged in to reply to this topic.