Home Forums General Issues Can't get CheckBox value with Certain Rules set?


Can't get CheckBox value with Certain Rules set?

  • I tried to set up a scenario where I could change a checkbox value depending on a certain post category. When I did this, once I would change a post’s category to the specified category the checkbox would show, but when ever I would try to check if the field is checked by doing an “if (get_field(“myfieldname”))”. But when I do so I get a return value of “bool(false)”. However if I set the rule to show the checkbox on a “page” it works fine. Can someone break down why this works one way and not the other.

  • Hi @webmasterladueschools-net

    Could you please share the JSON or XML export file of your field group and the PHP code you were using so I can test it out on my installation?

    If the PHP code is too long, you can always paste it here instead:

    Thanks 🙂

  • This reply has been marked as private.
  • Hi @webmasterladueschools-net

    Could you please tell me where did you put the code? Please keep in mind if you set the rule to “Post Category <=> is equal to <=> Category name”, then you need to execute the code in the single.php file.

    If you have Front page displays option set on “wp-admin > Settings > Reading” and set the rule to “page”, then executing it on the front page template would be possible. Another method is to set the rule to “Page Type <=> is equal to <=> Front Page”

    If you need to get the value on other pages where the fields are not assigned, you can pass the post ID instead. So, for example, if your front page has an ID of 99, you can get the value anywhere by using this code:

    get_field('special_news', 99);

    If those are not what you want, could you please explain your query in more detail?

    I hope this makes sense 🙂

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

The topic ‘Can't get CheckBox value with Certain Rules set?’ is closed to new replies.