Support

Account

Home Forums General Issues Show field value before update

Solved

Show field value before update

  • 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.

  • 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
    
    }
    
  • 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)

The topic ‘Show field value before update’ is closed to new replies.