0

I was diving in my Wordpress installation to start thinking in a future development and I did this query:

select * from postmeta where post_id = 1485433 and meta_key = 'qode_revolution-slider'

This query has as result 6 rows... identical, except for the meta_id value.

In fact, for test, I executed:

select post_id, meta_key, count(meta_id) as metas
from tpostmeta
where post_id > 0 
group by post_id, meta_key 
having metas > 1
order by post_id;

And I have several posts (more than 30) whit the same meta_key more than once... I have seen 2, 3, 6 and 8 times repeated some values...

Is it normal? I thought that each combination post_id/meta_key must be unique, and this was a wordpress core job..

Thanks you all, regards

0

No, it does not have to be unique. Whether it's a good practice to use it this way - that's another question you can ask that plugin authors. Here's the scenario:

  • you have a slider in an entry
  • slider has several slides
  • each slide is stored as meta

In this case, you will have couple records with the same post_ID and same meta_key (let's call it 'slide'). You can fetch them with get_post_meta( $post->ID, 'slide' ) into an array.

Personally, I would store all slides in a single meta as a serialized array. But I do see some use cases for storing repeatable data in separate meta records. For example, you might need to treat it meta_value_num in you meta_query, which will not work with serialized array data.

1
  • Thanks Ihor.Diving on the database, I saw that there are other values repeated, from plugins like yoast or qode slider... but also meta values from wordpress core, like _edit_last... this was weird for me... ok, I will think about that structure. Thanks!
    – msolla
    Nov 15 '16 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.