Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to add articles in batches through WordPress built-in functions

Shulou Source: shulou.com Published: 2022-06-01 23:52:41 11月16日 Update

This article mainly introduces how to add articles in batches through the built-in function of WordPress, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

Recently, the business needs to add a large number of articles to the website in bulk. Adding articles manually will definitely kill me, so I started looking for ways to add them in batches. In fact, the relevant contents of the article are already in the local database. The first way I thought of was to import the data directly into the online library through the sql statement.

So I passed.

INSERT INTO target_table (key1, key2...) SELECT key1', key2'... FROM source_table

The data is inserted into the online table. When you open the page, it's all garbled. So, I set the code again before inserting, and there is still a problem.

Since I am not good at sql, I adjusted my strategy. By chance, I found a built-in function of WordPress, 'wp_insert_post'. Yeah, that's him.

So I exported the target data to php_array, then introduced it into my script and added it to the database through the wp_insert_post function.

Foreach ($php_array as $item) {$arg = array ('post_title' = > $item [' title'], 'post_content' = > $item [' content'], 'post_excerpt' = > $item [' excerpt'], 'post_type' = >' post', 'post_status' = >' public', 'meta_input' = > array (' meta_key' = > meta_value')) Wp_insert_post ($arg);}

In this way, articles are added in batches in a "legal" way through WordPress, and custom columns can be added to meta_input, which is great.

Thank you for reading this article carefully. I hope the article "how to add articles in batches through WordPress built-in functions" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles data functions articles databases methods legal business garbled value interest content and at the same time manual way more first friends column Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Shulou Technology Apple Linux