Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6925713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:49:29+00:00 2026-05-27T10:49:29+00:00

I am trying to run a query to update the value of a custom

  • 0

I am trying to run a query to update the value of a custom field in a WordPress wp_postmeta table. The data looks like this:

meta_id     post_id     meta_key          meta_value
-------     -------     -------           ----------
1           1           start_date        2011-12-30
2           1           start_time        21:00
3           363         start_date        2011-12-29
4           363         start_time        21:00
5           363         _start_timestamp  2011-12-29 21:00

I would like to make a query to add a record with a meta_key value of _start_timestamp that combines the values of start_date and start_time for a given post_id, but only in the cases where the _start_timestamp was not already set.

Before going into the INSERT query, I tried to get a SELECT query that would show the stuff I wanted. I managed to make a SELECT query that returns the post IDs that HAVE the _start_timestamp defined, but can’t figure out how to get the ones that do not have it defined.

This is what I have:

SELECT 
a.post_id, 
CONCAT(a.meta_value, ' ', b.meta_value), 
c.meta_value
FROM 
wp_postmeta a
INNER JOIN wp_postmeta b ON a.post_id=b.post_id
INNER JOIN wp_postmeta c ON a.post_id=c.post_id
WHERE 
a.meta_key = 'start_date' 
AND b.meta_key = 'start_time' 
AND c.meta_key='_start_eventtimestamp'

This returns

post_id     CONCAT(a.meta_value, ' ', b.meta_value)     meta_value
363         2011-12-29 21:00                                2011-12-29 21:00

How can I specify to get the results only when _start_timestamp is not present in the meta_key column for a given post_id? In this case, it should return only the post_id 1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:49:30+00:00Added an answer on May 27, 2026 at 10:49 am

    Try:

    SELECT 
    a.post_id, 
    CONCAT(a.meta_value, ' ', b.meta_value), 
    c.meta_value
    FROM 
    wp_postmeta a
    INNER JOIN wp_postmeta b ON a.post_id=b.post_id
    LEFT JOIN wp_postmeta c ON a.post_id=c.post_id AND 
                               c.meta_key='_start_eventtimestamp'
    WHERE 
    a.meta_key = 'start_date' 
    AND b.meta_key = 'start_time' 
    AND c.post_id is null
    

    EDIT: An alternative approach:

    SELECT post_id,
           '_start_timestamp' as meta_key,
           concat(max(case meta_key when 'start_date' then meta_value end), ' ',
                  max(case meta_key when 'start_time' then meta_value end) 
                 ) as meta_value
    from wp_postmeta
    group by post_id
    having max(case meta_key when 'start_date' then meta_value end) is not null and
           max(case meta_key when 'start_time' then meta_value end) is not null and
           max(case meta_key when '_start_timestamp' then meta_value end) is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to run this query to Update member points When the member points
I'm trying to run the following query using phpMyAdmin: UPDATE TABLE x SET `number`
I'm trying to run an update query that updates one table based on rows
Hi I am trying to run this query in SQL but it is not
Hey guys I am getting this exception when trying to run the query Column
I'm currently trying to run a LINQ query over a MS SQL database. This
I am trying to run this update statement but informix doesn't allow me to.
I'm trying to create a query that will update the value of rgn_no and
I am trying to update a field in a table by increasing its integer
I'm trying to update the custom meta for all WordPress posts where another custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.