Before Gutenberg I added meta_fields like "_my_integer_value" and added them to the post. I could query with something like this:
$args = array(
'post_type' => 'post',
'orderby' => array( 'meta_value_num' => 'DESC', 'date' => 'DESC' ),
'meta_key' => '_my_integer_value',
'posts_per_page' => '300',
'order' => 'DESC'
);
Now I made a block that saves its content to the html of the block.
block.json
"attributes": {
"my_integer_value": {
"type": "string",
"source": "html",
"selector": "span.value",
"default": 5
}
},
What is the best practice to use blocks and make information in them sortable in queries? Can I save the contents to the post meta somehow? Is there another option to save content in block that can be queried? This allows only for queries for posts that have this block but I can't sort them: WP Query by Gutenberg block and get its attribute
WP_Query
is concerned. You can search inside a post but it is no different to searching for words in a paragraphadd_post_meta
adds post meta, whereas taxonomy/terms are a custom taxonomy like categories/tags. Post meta is fast when you already know the post ID. Taxonomy tables are purpose built for finding post IDs when you know the term ( the thingmeta_query
does but potentially hundreds of times faster and more scalable and using dedicated tables )