I created a plugin which has a shortcode that displays a button in a form. I would like to track the button clicks with an onclick() script and save the amount of clicks to a meta field. I am just not sure where to save this data. I don't want this data to be saved to a posts meta field, as this isn't post specific. Should such data be saved to the wp-options table? What's the best way to do this?


  • Depending on the amount of details you want to save, you could also create a table for it. – user167290 May 22 '19 at 6:29
  • Thanks for your input. I only need to save 2 pieces of data so I think wp-options should suffice. Please correct me if I'm wrong. – harvey May 22 '19 at 19:02

If it's not post specific then it should be saved as an option in wp_options with add_option() or update_option().

| improve this answer | |
  • Thank you. Would there be anything unsafe about displaying the info I want to save on the frontend? – harvey May 22 '19 at 4:41
  • Not if you properly sanitize and escape it. But that also applies to post meta. – Jacob Peattie May 22 '19 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.