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.
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:
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)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users