Support

Account

Home Forums General Issues Show field value before update

Solved

Show field value before update

    • Vasili

    • July 17, 2013 at 7:00 pm

    Hi Elliot, i have created a radio type field with two options: Enable or Disable the sidebar on current post. As you understand this field appears on post add/edit page. The default value is Enable, so when you visit the single post you should see the sidebar, the thing is that you don’t, but only if you update the post. It’s great for new posts, but what to do with old posts? I tried using filters, but i guess it’s not the way. Can you please tell me how can i retrieve the Enable value before it saved to the Data Base.

    Thank you.

    • bootsz

    • July 18, 2013 at 11:26 am

    I suspect the issue is with the logic you’re using in the template itself. Let’s say the field is called “enable_sidebar” and the options are “enable” & “disable”. Existing posts will not have any value stored for the field “enable_sidebar” until you re-save them, so you need to count the scenario of having no value as equivalent to “enable”.

    Something like this should do it:

    
    if (!get_field("enable_sidebar") || get_field("enable_sidebar") == "enable") {
    
    //sidebar here
    
    }
    
    • Vasili

    • July 18, 2013 at 8:36 pm

    Thank you very much for your help bootsz, much appreciate it. It was the perfect solution.

Viewing 3 posts - 1 through 3 (of 3 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.