Hide Posts with Boolean Custom Field On True

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 Ernest Marcinko 1 year, 1 month ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #36633
    capstonedesign42
    capstonedesign42
    Participant

    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

    #36685
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #36712
    capstonedesign42
    capstonedesign42
    Participant

    Hello. 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!

    #36720
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    It 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.png

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #36736
    capstonedesign42
    capstonedesign42
    Participant

    Hi. Unfortunately, this solution does not work. Do you have any other recommendations?

    #36742
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    It 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.png

    That 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 :)


    #36778
    capstonedesign42
    capstonedesign42
    Participant
    You cannot access this content.
    #36799
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Oh 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.png

    The 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 :)


    #36808
    capstonedesign42
    capstonedesign42
    Participant

    That did it! Thank you!

    #36811
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.