I need a SQL query that I can run in PHPmyadmin that adds a custom field (with a value) 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With