0

Here's the sql statement I tried for adding data from one table to another.

INSERT INTO wp_postmeta(`post_id`,`meta_key`,`meta_value`) VALUES((SELECT ID FROM wp_posts tb WHERE tb.post_type = 'support'),'category_order','0')

Basicaly I want to add rows to the wp_postmeta table. I want to add two static values, meta_key and meta_value. But I also want to add post_id which should be derived from the ID of each row in wp_posts. This doesn't seem to work when there are multiple rows returned from the SELECT statement.

Thanks for the help.

3
  • 1
    SELECT ID, 'category_order', '0' FROM.... Commented Nov 10, 2014 at 18:06
  • @PatrickQ this doesn't make sense. These fields do not all exist in the wp_posts table. Only ID does. Commented Nov 10, 2014 at 18:08
  • 1
    That's why you select them as strings, not as column names. Commented Nov 10, 2014 at 18:08

2 Answers 2

2

Try this instead

INSERT INTO wp_postmeta(post_id,meta_key,meta_value) SELECT ID, 'category_order','0' FROM wp_posts tb WHERE tb.post_type = 'support'

Sign up to request clarification or add additional context in comments.

Comments

0
INSERT INTO wp_postmeta(`post_id`,`meta_key`,`meta_value`) SELECT ID, 'category_order','0' FROM wp_posts tb WHERE tb.post_type = 'support'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.