Web Shakehands
Web Shakehands

Language


How to pass array to the database by using "update_option". WordPress Plugin Creation



Update_option is a WordPress function that can easily pass information to the database.

Codex Page
https://wpdocs.osdn.jp/Options_API

Well, I think that when you want to put information in the database, We often want to pass in as an array.

How do you do this?

Please see the code below.

The point is to register "filename" as an array with "update_option" first.

There are various ways to do this, but one example is to complete this registration when the plugin is activated.

Method when plugin is activated
register_activation_hook

get_option is a function that pulls out registered information from the database.
It is assigning "filename" to $exist.

Next, use array_push to assign $exist by adding as an array.
Then, the array will be added to the database by using update_option again.

When you repeat this array_push, you can put more information on the array, and able to update by using update_option.

Here, $ _POST ['filename'] is a sample method, so please create with your own here.

(Also, $ _POST ['filename'] is not sanitized here.)

When you want to output the information from the database that is registered by array, use the normal "foreach" on the HTML side.



このエントリーをはてなブックマークに追加

This article title

How to pass array to the database by using "update_option". WordPress Plugin Creation

Previous article How to create a database table from a WordPress plugin


WordPress Plugin creation Article !

2019-07-25 Get information from the WordPress database using wpdb->prepare [plugin production] NEW!


2019-07-23 How to pass array to the database by using "update_option". WordPress Plugin Creation


2019-07-17 How to create a database table from a WordPress plugin


2019-07-13 Use current_time () when dealing with WordPress dates!


See all the articles list

Just enter your E-mail and you will receive free
mail magazine about how to make your website etc.
E-mail:
  

Go to top