Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#61695 new enhancement

Suggestion: Add a post_type column in the wp_postmeta table

Reported by: rajinsharwar's profile rajinsharwar Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

An Enhancement: I am wondering if we can add a post_type column in the wp_postmeta table. This would allow us to query for the mey keys using the post_type column, instead of querying each individually with post_ids.

A simple use case is, I was building a contact list plugin. There, I had a CPT of "my_emails". Now, in that CPT, there were multiple meta fields of "email", "first_name", "last_name" etc. Now to fetch all the meta fields of "email", I need to query through the whole wp_postmeta table to find instances of "email" meta_key. It would have been much easier and faster I believe if we could have a post_type column as well in the table, which tells the post_type that meta is of.

Change History (1)

#1 in reply to: ↑ description @debarghyabanerjee
5 months ago

Replying to rajinsharwar:

An Enhancement: I am wondering if we can add a post_type column in the wp_postmeta table. This would allow us to query for the mey keys using the post_type column, instead of querying each individually with post_ids.

A simple use case is, I was building a contact list plugin. There, I had a CPT of "my_emails". Now, in that CPT, there were multiple meta fields of "email", "first_name", "last_name" etc. Now to fetch all the meta fields of "email", I need to query through the whole wp_postmeta table to find instances of "email" meta_key. It would have been much easier and faster I believe if we could have a post_type column as well in the table, which tells the post_type that meta is of.

Hi @rajinsharwar, if we add a column of post_type to the post-meta table, that would go against the concept of Normalization in SQL. However, I understand your point and I guess that for certain use-cases it would reduce multiple database queries.

Note: See TracTickets for help on using tickets.