[wp-hackers] MySQL queries to add to wp_postmeta
mikeschinkel at newclarity.net
Mon Jul 12 23:26:18 UTC 2010
So you want a bulk insert statement to add the meta_key with a default value for every one that's missing one? Why not default the value in PHP code rather than take up disk space?
That said, I think this is what you asked for, let me know if not:
INSERT INTO wp_postmeta2 (post_id,meta_key,meta_value)
WHERE ID NOT IN (SELECT post_id FROM wp_postmeta2 WHERE meta_key = 'my_custom_key')
P.S. This can be written several ways, I wrote this to try to make it the most obvious.
On Jul 12, 2010, at 7:14 PM, Joel Fisher wrote:
> Basically it is just a custom field.
> I want every post that currently does NOT have the meta_key = members
> to get it and also set the meta_value = false.
> Does that make sense?
> So, it is the same key and the same value for all posts that does not
> currently have it set.
> Linkedin: http://www.linkedin.com/in/jfisher
> Follow: www.twitter.com/joelmoney
> On Mon, Jul 12, 2010 at 7:12 PM, Mike Schinkel
> <mikeschinkel at newclarity.net> wrote:
>> How are you going to generate the queries? In an Excel spreadsheet and run them all, or by calling a function that issues the SQL, or something else. IOW, where is your metadata coming from?
>> On Jul 12, 2010, at 7:08 PM, Joel Fisher wrote:
>>> I have a ton of posts that I need to add a meta_key and meta_value too.
>>> Some posts, it already exists so I don't want to overwrite.
>>> Basically I want to add it to ALL posts that do NOT have it already.
>>> Can someone point me to a MySQL query or alternative method to add this data?
>>> Linkedin: http://www.linkedin.com/in/jfisher
>>> Follow: www.twitter.com/joelmoney
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers