Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for storing CPT metadata in Custom Database Tables #3759

Closed
cr101 opened this issue Dec 2, 2017 · 3 comments
Closed

Support for storing CPT metadata in Custom Database Tables #3759

cr101 opened this issue Dec 2, 2017 · 3 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Extensibility The ability to extend blocks or the editing experience Framework Issues related to broader framework topics, especially as it relates to javascript [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Enhancement A suggestion for improvement.
Milestone

Comments

@cr101
Copy link

cr101 commented Dec 2, 2017

As an example, we have two CPTs, Books and Authors, and we would like to store the Books metadata (i.e parent_id, isbn, subtitle, average_rating, ratings_count, publication_date, num_pages, bisac_code, author_id, etc) in a custom DB table "Books" and also store the Authors metadata (i.e works_count, date_of_birth, fans_count, average_rating, etc) in a custom DB table "Authors".

We would then like to query the data like so:

SELECT p.post_id, p.post_title, p.post_content, b.subtitle, b.average_rating, a.post_tile as author_name
FROM wp_posts as p
INNER JOIN books as b ON p.post_id = b.parent_id
INNER JOIN authors as a ON b.author_id = a.id
WHERE b.average_rating => 3 AND YEAR(b.publication_date) => 2007 AND bisac_code = 'FIC009050' AND a.average_rating => 3

Storing all the CPTs metadata in wp_postmeta is not an option because searching over 1 million rows would be very slow and doesn't scale and it's the reason why WooCommerce is moving orders and products to custom DB tables as well.

Will I be able to add custom fields/meta blocks to the two CPTs in Gutenberg and then save that meta data in custom database tables?

@mtias mtias added [Feature] Extensibility The ability to extend blocks or the editing experience Framework Issues related to broader framework topics, especially as it relates to javascript [Feature] Block API API that allows to express the block paradigm. labels Jan 4, 2018
@pmgarman
Copy link

pmgarman commented Jan 6, 2018

You already can do this without the need for changes to Gutenberg. You can do it now without Gutenberg actually. We do it on projects of ours semi regulrly.

@cr101
Copy link
Author

cr101 commented Jan 7, 2018

@pmgarman Yes, you can already save the CPTs metadata in custom db tables without Gutenberg but I'm fairly certain that you can't yet do that with Gutenberg.

@gziolo gziolo added this to To do in Extensibility Jan 31, 2018
@gziolo gziolo added the [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later label Feb 28, 2018
@gziolo gziolo removed the [Feature] Extensibility The ability to extend blocks or the editing experience label May 14, 2018
@gziolo gziolo removed this from To do in Extensibility May 14, 2018
@mtias mtias added Future [Feature] Extensibility The ability to extend blocks or the editing experience labels Oct 7, 2018
@mtias mtias added this to the Future: 5.1 Onwards milestone Oct 12, 2018
@designsimply designsimply added the [Type] Enhancement A suggestion for improvement. label Jan 8, 2019
@youknowriad youknowriad modified the milestones: WordPress 5.x, Future Jan 9, 2019
@youknowriad youknowriad modified the milestones: Future, Future: Phase 2 Jan 21, 2019
@youknowriad
Copy link
Contributor

Building blocks that store things in several CPT fields is possible using the EntityProvider and useEntityProperty hook. You can check how PostTitle, PostExcerpt... blocks work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Extensibility The ability to extend blocks or the editing experience Framework Issues related to broader framework topics, especially as it relates to javascript [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

6 participants