Backend ACF True/False value as condition for frontend

I’m trying to set this up:

  • a True/False ACF field (or whatever else works) in the edit page of one of my wp pages;
  • default value should be 0
  • through a condition, IF value is 0, the section SHOULD NOT show up
  • IF value is 1, the section SHOULD show up

If I test the field with a {{acf:FIELD_NAME}} string, it returns the correct initial value (in Cornerstone as in frontend) as 0, but when I change the value to 1 from the backend and refresh the frontend, it updates the test value but, apparently, not the value that switch the condition (because the section still doesn’t show up.

By the way, If I use the True/False field, I get the 1 value but not the 0 value (the {{acf:FIELD_NAME}} ain’t returning anything, like the value was NULL.
If I use a couple of Radio Buttons, I get both the values showing on the test string, but the condition still ain’t working.

Can you help?

Thanks
Alessandro

Hey Alessandro,

Instead of using string, you should try the number in comparing the true/false data. If it doesn’t work, we need to check your setup. To do that, please provide the following information in a Secure Note.

  • WordPress Login URL
  • Admin level username and password
  • Page URL in question

You can find the Secure Note button at the bottom of your posts.

Hope that helps.

Thanks @marc_a. Sorry for the late answer.
I just added the infos the the secure not of previous post.

Thank you for the update.

We couldn’t edit the Speciale section in the Home page for some reason, so we created a test page called “Test ACF Condition” (see secure note). We added the condition “attiva” to the Button element. Please note that “No” returns 1, and “Si” returns 2.

Let us know if you need more info.

Warm regards.

Yea, sorry. The “Speciale” section was temporary hidden by a css code in the global css style sheet. I forgot that.

Anyway, the string you used as variable really looks like the one I did write but I managed to paste it in the home page and it works now. Probably I wrote it wrong, missed some bracket and stuff :wink:

Thanks for your help fellas.

@Ismael will this work the same way with True/False switch?

(now the “Speciale” section in Home page is no more hidden by css but with the condition working)

Hey @pandinsky,

You can structure your layout in the following manner:

Use a True/False field to control the visibility of a section, with the default setting as unchecked.

When unchecked, the section will be visible, and when checked, the section will be hidden.

In this case, the condition should be set as follows: {{dc:acf:post_field field="your_acf_field"}} == 1 , which is a number type.

Hope that helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.