Home Forums General Issues Programatically update radio button option


Programatically update radio button option

  • Hi,

    So heres my issue, I have a custom post type of Stock and this is using acf to provide some additional fields. These for the most part are working but I cannot get either the radio button or a select to update correctly. Heres What I’m trying to do:
    The acf field is called show_on_homepage and it has its conditions set as Yes and No (also tried with Yes : Yes and No : No)
    In my code I am trying to set this as Yes:
    update_field('show_on_homepage', 'Yes', $post->Id);
    However it doesn’t update the value on the post with the $post->ID.

    Am I missing something here? I should point out that other fields like this are working:
    update_field('stock_id', 'CF-97', $post->ID);

    As mentioned I also tried with a select and this didn’t work either. Can anyone give examples for both ways (Select or Radio Buttons) please?



  • What is the field type again?

    What are the field settings? choices etc.

  • Hi John,

    My responses:

    What is the field type again? show_on_homepage is a radio button (but also trying to get this to work if it was a select – I assume that the process is the same for both of these).

    What are the field settings? choices etc. The choices are Yes and No (I tried also using Yes : Yes and No : No but no different)

  • Have you tried using a True/False field? It may be far easier to toggle you the value of 1 or 0

  • So it turned out to be an incorrect named field (shown_on_homepage) and everything else was right, case dismissed.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.