Gutenberg Block: Query for posts with blocks and sort by attributes


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.


"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

Marc 1 year 2021-11-19T08:56:22-05:00 0 Answers 0 views 0

Leave an answer