Support

Account

Home Forums General Issues How can I query on the postmeta table for two keys Reply To: How can I query on the postmeta table for two keys

  • Is there a better way to get this or do I simply have to run the update three times. The issue is that 3 of the columns I need are in the meta_key value.

    [Add most of the info from post and also Venue]

    INSERT into wp_venue_title_startdate (post_id, meta_post_id, post_author, post_title, meta_venue, post_type, post_status)
    SELECT p.id, m.post_id, p.post_author, p.post_title, m.meta_value,p.post_type,p.post_status
    FROM wp_posts p, wp_postmeta m
    WHERE m.post_id=p.id AND m.meta_key=”venue” AND p.post_status=”publish”;

    [Add User Name]
    UPDATE wp_venue_title_startdate tbl_sd
    INNER JOIN wp_users u
    ON tbl_sd.post_author = u.id
    SET tbl_sd.user_login=u.user_login

    [Add Start Date]
    UPDATE wp_venue_title_startdate tbl_sd
    INNER JOIN wp_postmeta m
    ON tbl_sd.post_id = m.post_id
    SET tbl_sd.meta_start_date=m.meta_value
    WHERE m.meta_key=”start_date”

    [Add END Date]
    UPDATE wp_venue_title_startdate tbl_sd
    INNER JOIN wp_postmeta m
    ON tbl_sd.post_id = m.post_id
    SET tbl_sd.meta_end_date=m.meta_value
    WHERE m.meta_key=”end_date”