Answer the question
In order to leave comments, you need to log in
How to create an entry in the wp_postmeta table with a condition?
Greetings!
There is a wp_postmeta table, the table has the following columns:
META_ID / POST_ID / META_KEY / META_VALUE
The table already contains a large number of records, among which there are records in which the META_KEY="related_p" field already exists and is filled in, no matter what META_VALUE value, though with empty.
For example:
META_ID / POST_ID / META_KEY / META_VALUE
11114 / 2222 / related_p / 6666
11115 / 2222 / price / 123
But there are also entries that do NOT have META_KEY="related_p"
For example:
META_ID / POST_ID / META_KEY / META_VALUE
11116 / 3333 / price / 456
How to write an sql command to do the following:
If in the wp_postmeta table, the record with POST_ID="3333" does NOT have the META_KEY="related_p" field, then create such a row, with auto-increment of the META_ID column, POST_ID="3333", META_KEY="related_p" and META_VALUE="" ( empty value).
Thank you!
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question