www.webdeveloper.com
Results 1 to 2 of 2

Thread: Problem Select wordpress posts with given text string and add a custom field to them?

Hybrid View

  1. #1
    Join Date
    May 2009
    Posts
    100

    Problem Select wordpress posts with given text string and add a custom field to them?

    Hey guys.. I made this SQL query which selects post Ids by all posts containing a keyword then attempts to add a custom field but I get a syntax error.

    Bit lost so all help appreciated thanks.

    Code:
    INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
    SELECT ID FROM wp_posts WHERE post_content LIKE '%Customer Reviews%' AS post_id,
           'customer_reviews' AS meta_key, 
           'On_or_delete' AS meta_value
    FROM   wp_posts 
    WHERE  ID NOT IN
           (SELECT post_id 
            FROM wp_postmeta 
            WHERE meta_key = 'customer_reviews')
           AND post_type = 'post';

  2. #2
    Join Date
    Jul 2013
    Posts
    29
    What is the error? I guess you cannot insert to the same table you are selecting from.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles