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 post metadata inside blocks #1842

Closed
felixarntz opened this issue Jul 10, 2017 · 6 comments
Closed

Support post metadata inside blocks #1842

felixarntz opened this issue Jul 10, 2017 · 6 comments
Labels
[Feature] Block API API that allows to express the block paradigm.

Comments

@felixarntz
Copy link
Member

Issue Overview

With the current editor, the general practice (whether that's good or bad) is to use post metadata for anything custom that should be displayed in the post content. Most of this data can become information that is simply entered into a specific field of a specific block type. By parsing the blocks from the post content, it is also possible to retrieve such a specific piece of data, so we're good up to this point.

However, there's one thing that is currently not possible: Querying posts by such a specific piece of data. At the moment, since everything is stored in metadata anyway, we can use a WP_Query and its meta_query functionality: For example, if we have a meta field for entering an email address (stored under a specific meta key), we can then query all posts where "[email protected]" has been provided for that field / key.
Now with Gutenberg, if we have a block type (let's say we call it "Contact Data") where one can enter an email address, there's no way to properly query for all posts that have a specific email address in there, since that information is only available somewhere in the content. Of course we could just provide the email address we wanna query by as the search parameter, but that would simply search the entire post content, not only that specific type of email field in our "Contact Data" block).

Possible Solution

A possible solution for this could be to allow specific block types (at the code level) to register one of its "attribute field" to map to a specific post meta key. If the user enters data into that field, the value would then automatically be saved as metadata under that key (of course in addition to it being part of the post content, as usual). This would allow querying by such data.
It's important to highlight that registering such a meta key should only be used in cases where querying for it makes sense. Otherwise, if everyone registered all their attributes as metadata, the postmeta database table would become too cluttered.

An alternative (that is possible now already) is to still have a metabox for the data somewhere, and only use the block type to reference that meta key. That would however require the block to have a PHP callback, furthermore I think it would be confusing to the user to enter that metadata somewhere and then also having to insert a block that displays that data. Given the fact that Gutenberg demotes meta boxes, that alternative would be even worse. So I think my above suggestion of mapping specific block type fields to specific post meta keys is much nicer.

I hope that explanation is clear enough, as it's a somewhat complex topic. If not, please ask, I'm happy to clarify.

@westonruter
Copy link
Member

➕ for this:

A possible solution for this could be to allow specific block types (at the code level) to register one of its "attribute field" to map to a specific post meta key. If the user enters data into that field, the value would then automatically be saved as metadata under that key (of course in addition to it being part of the post content, as usual). This would allow querying by such data.

It's very similar to what I've brought up in #1754.

@mtias mtias added the [Feature] Block API API that allows to express the block paradigm. label Aug 18, 2017
@tharsheblows
Copy link
Contributor

A more general solution would be to allow the blocks to have persistent ids (opt in persistent ids), eg a block looks like something like this. Then if you have the post id somewhere like localised in the footer maybe, that's enough to do whatever you want with the content of the block — get it from postmeta, a custom table, an api etc.
screen shot 2017-09-05 at 17 38 51
I've tried this out in a little plugin here mainly to see how it works and it was straightforward. It also gets away from this which I can see being a real problem too:

It's important to highlight that registering such a meta key should only be used in cases where querying for it makes sense. Otherwise, if everyone registered all their attributes as metadata, the postmeta database table would become too cluttered.

@mtias
Copy link
Member

mtias commented Nov 20, 2017

This works now — you can specify attributes as being meta. The downside is it also requires a register_meta call that enables show_in_rest.

@mtias mtias closed this as completed Nov 20, 2017
@Lewiscowles1986
Copy link
Contributor

@mtias is there a link to the commit in which this happened or any resource describing in more detail your last comment?

@Soean
Copy link
Member

Soean commented Feb 23, 2018

@Lewiscowles1986 You can find the documentation in the handbook: https://wordpress.org/gutenberg/handbook/block-api/attributes/#meta

@emfluenceindia
Copy link

I am a late comer to this thread. I am trying my hand for the first time with metadata but not yet successful.
I have posted my question at https://stackoverflow.com/questions/52167808/gutenberg-meta-information-is-saved-as-html-comment-in-post-content-field

Please help me understanding what I am doing wrong.

Thanks!

Tug pushed a commit that referenced this issue Feb 28, 2020
…rd-landscape

Avoid fullscreen text entry UI in landscape mode
Tug pushed a commit that referenced this issue Mar 19, 2020
#1989)

* Revert "Merge pull request #1842 from wordpress-mobile/issue/1829_soft-keyboard-landscape"

This reverts commit 5041096, reversing
changes made to ddb8b3f.

* Remove release note for reverted landscape mode change
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.
Projects
None yet
Development

No branches or pull requests

7 participants