I want to learn creating custom Brics, thought to start off with a Bric that allows to populate with dynamic data from a WP Site. I decided to go with Custom Fields.
So my idea is this:
Create a bric that allows the user to insert the Slug of the Custom Field, and then the bric would populate with the value from that field.
Just like we can already do this with the Data settings for (example) headings in Blocs, where we can chose to populate the heading with the post title.
I found that is cool but restricted, because for example I can not populate a
span item with similar dynamic data, and sometimes we need a Heading (or anything, really) to be comped of several datasets, like
WP Post Title + WP Custom Field + Anything else.
So I thought to create a custom bric that (for the start) just lets me pass a Custom Field Slug.
In WP I would use the function
get_post_meta($post_id, 'field-slug', $array = false); to get the field value of the custom field with slug
field-slug and then I would
echo that in a template.
I found the Brics do not seem to support adding a PHP function that later would be executed in the Theme or template.
I know that Blocs already supports literally any PHP function in the code bric, but I just want to try to create my own brick so I can late develop several dynamic Brics to be used for WP.
I read thru the DOC and find that I am not clear how I would go about this.
I checked the inbuilt Blocs bric
WP Content and saw that literally the only thing that makes it work is this piece of code:
<div wp-text-data-feed="%WP_content%"> Wordpress page or post content will be displayed here. </div>
That does not really “help” me in the sense that I know
%WP_content% is an inbuilt “ShortCode” (or better, placeholder) - and the underlying code for this must be stored in the app itself, because I do not see it in the Brics builder/editor. Obviously it must use WP API, and indeed in the exported theme, this placeholder simply gets replaced with the WP API
However, I see nothing in the Bric itself that “tells” blocs to do that, hence I assume it is coded elsewhere in the actual app.
I hope this is not too confusing, and that someone could point me to the right direction?
Once I get the grasp of this I’ll flood you with custom Brics
Yes I know Blocs already supports a “Custom fields” WP Data setting, however, what for taxonomies, and more complex custom fields - or for future things, for example pulling data from custom database tables (for relationships) and such. I just want to start easy, that’s why I chose “Custom Fields”