I have about 200 pages and 400 posts on my WP site. And I need to add one custom field (sidebar_config: left-sidebar) to all pages and posts.

I have this for SQL query in PhpMyAdmin:

INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, 'sidebar_config', 'left-sidebar' FROM wp_posts
WHERE post_type = 'post, pages'

The problem is that some of pages/posts already have this field. How do I need to modify my query to avoid adding duplicates in DB table?

Read more here: Add a custom field via PhpMyAdmin to all posts and pages avoiding duplicates


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: