开发者

Wordpress & SQL: Adding a custom field to all posts

开发者 https://www.devze.com 2023-01-04 22:14 出处:网络
I need a SQL query that I can run in PHPmyadmin that adds a custom field (with a v开发者_如何学Calue) to all existing posts.

I need a SQL query that I can run in PHPmyadmin that adds a custom field (with a v开发者_如何学Calue) to all existing posts. Can anyone help? Is this even possible?


You can do this by inserting into the postmeta table using a select query on the posts table.

In the example below I use wp_ as my table prefix, your setup may differ.

insert into wp_postmeta (post_id, meta_key, meta_value) 
select ID, 'my-key', 'my-value' from wp_posts where post_type = 'post';


Yes, this is possible, but it is inadvisable. Your data could be lost the next time you upgrade. If you're not planning on upgrading, then you're leaving gaping security holes in your site. The recommended way to do this is to use the postmeta table. This is what it exists for.

EDIT

Now that I better understand the question, ignore the part above. See comments for more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消