Create and query Wp

Asked

Viewed 239 times

2

Is it possible to create a table in the Wp database to enter values and change them, or would it block me? I wanted to create a simple table only to validate, insert a number and if necessary to change this number.

  • Your question is not very clear, but responding to the letter is possible yes, you can create a table and change your data but if it is to manipulate the data of this table by wp admin panel you will have to at least create a plugin following the architecture of wp.

1 answer

0

You need to create a table within the Wordpress database. You can use the "dbDelta" function to create the table structure and the "wpdb" api for CRUD (Create, read, update and delete occurrences).

  1. Run SQL via dbDelta to create table: https://codex.wordpress.org/Creating_Tables_with_Plugins. Or, if easy, create the table via Phpmyadmin itself.
  2. Run SQL via $wpdb to insert, read, update or delete data from the created table: https://codex.wordpress.org/Class_Reference/wpdb

I think this should help.

  • Only one doubt this table I can freely edit ?

  • To pass values only create that way $value = 1;

  • add_option ($ option, $ value , $ obsolete =, $ autoload = 'yes');

  • To create you use: add_option( 'nickname', 'Leo' ); and then you query with get_option( 'nickname' ); or change with the method: update_option( 'nickname', 'Leooooo' );

  • But how will I be able to pull to make sure that this is a true value for that user? Because by doing this way of the appearing that I can even create However becomes static the value and will be the same value to all, this is what happens?

  • The value is the same for all users, static. This api should be used for your application settings. To manipulate custom tables I changed my answer. See if that’s it. abs!

  • Can you confirm me if I got it right, I create a variable with sql commands for my structure needed for my database, use the native wp variable for this and for this to work I do the add_option command, but it won’t create a loop and create several tables or not? another doubts my structure to create the added database within Fuctions.php itself?

  • Hi @Fernando, actually the "Options" api is something else. From what I understand you will need more freedom to manage the data, so you have to create a table yourself. You can create the table via phpmyadmin and then manage by $wpdb (insert, read, update, delete lines).

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.