0

I have a dropbox button that user interact with it to get some data like video's id and video's name using Js code.

What I want to do is insert these data in the database using pair data structure and calling it in when it needed.

I found out that I can do this using add_metadata or add_options which one shoukd i use? and is there better sutiable way.

Second thing: I have the button here implemented through add_shortcode using a tag but I want to replace the tag with html class in the page because I've to to write the tag like [] to add the button.

The button

New contributor
Steve is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

1

The right place to store the data depends on how you will be using the data. From the context, it sounds like metadata might be the right place. There is usermeta if the data relates to one of your site users, or postmeta if the data relates to a specific post/page/CPT.

Options are best reserved for data that affects the site as a whole. So, if you were going to use the data to populate a video that appears sitewide, options would be an appropriate place to store the data. But the options table can tend to get bloated and impact site performance, so it's especially inappropriate if the data doesn't relate to the site as a whole, or a large part of the site.

4
  • Thanks this's very clear, but now for this data that I want to insert should I create the new columns for the data manually? or can I create just one time in the code? because these data is new functionality that not have prefix in wordpress database. May I ask for the other part can I use add_shortcode with with a html class for example if I have specfic html class in a wordpress website page can I use instead of doing and adding [tagname] in the page then pass the name to add_shortcode function? –
    – Steve
    Jun 22 at 16:07
  • 1
    Adding metadata or options does not require creating any new columns in the database. You simply use add_user_meta(), add_post_meta(), or add_option() and WP stores it within its existing columns in existing tables. It is possible to add your own custom tables to store plugin data if you have a lot to store. For the shortcode question, I would recommend asking a new WPSE question as the site is really built to handle one question/answer pair at a time. :)
    – WebElaine
    Jun 22 at 16:18
  • For example the default wp_usermeta has 4 columns, now if i want to insert my new data then I have to create my new colums but for a plugin dev sake this will be absurd if it's gonna be done manually. So I think i need to create using the code just one time run. Am I correct or am i missing something?
    – Steve
    Jun 22 at 16:50
  • No, when you insert your data you would do it within the existing columns. The meta_key will be the name you call the data, and the meta_value is the actual data itself. There is rarely a need to extend Core tables, and it's usually wiser to add a separate table rather than change any Core db structure.
    – WebElaine
    Jun 22 at 18:32

Your Answer

Steve is a new contributor. Be nice, and check out our Code of Conduct.

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.