Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Hide Posts with Boolean Custom Field On True
This topic contains 9 replies, has 2 voices, and was last updated by Ernest Marcinko 1 year, 1 month ago.
- AuthorPosts
- February 10, 2022 at 10:23 pm #36633
Hello. 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 #36685Hi 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
Best,
The JSON encoded value of the boolean values includes the strings “true” and “false”, so that should match it.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
February 13, 2022 at 7:55 pm #36712Hello. 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 #36720It 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
Best,
..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.png
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
February 14, 2022 at 8:37 pm #36736Hi. Unfortunately, this solution does not work. Do you have any other recommendations?
February 15, 2022 at 1:04 pm #36742It 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.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
February 16, 2022 at 5:55 pm #36778You cannot access this content.February 17, 2022 at 4:59 pm #36799Oh 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.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
February 17, 2022 at 7:20 pm #36808That did it! Thank you!
February 17, 2022 at 8:38 pm #36811You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.