[wp-hackers] MySQL queries to add to wp_postmeta
Mike Schinkel
mikeschinkel at newclarity.net
Mon Jul 12 23:32:03 UTC 2010
Sorry, that was my code with a test table. Should have been:
==========
INSERT INTO wp_postmeta (post_id,meta_key,meta_value)
SELECT ID,'my_custom_key','false'
FROM wp_posts
WHERE ID NOT IN (SELECT post_id FROM wp_postmeta WHERE meta_key = 'my_custom_key')
==========
On Jul 12, 2010, at 7:26 PM, Mike Schinkel wrote:
> 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)
> SELECT ID,'my_custom_key','false'
> FROM wp_posts
> 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.
>
> -Mike
>
>
> 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.
>>
>>
>> joel.fisher
>> www.flushinc.com
>>
>> 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?
>>>
>>> -Mike
>>>
>>> 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?
>>>>
>>>> Thanks.
>>>>
>>>>
>>>>
>>>> joel.fisher
>>>> www.flushinc.com
>>>>
>>>> Linkedin: http://www.linkedin.com/in/jfisher
>>>> Follow: www.twitter.com/joelmoney
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list