• Hello,
    I have a general question on how to use WP_Query with blocks attributes.
    I will create one block with many values to replace my metabox:
    – Custom post ID,
    – Taxonomies
    – text

    I would like to know how to use wp_query to search on those values? I do not find any information very clear on that. Do I have to keep the metabox and add it to a bock or can I completely switch to the block and adjust my query? but in this case which object I have to use on the WP_Query?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You cannot use WP_Query directly. Block interactivity is running client side and WP_Query runs server side. Your block can make can make REST API requests to get any data it needs from the server.

    Thread Starter elboz

    (@elboz)

    Thanks for your answer,
    but I do not understand. When I generate my page I am on server side. So when I use wp_query to select my articles also. And it is when I generate the page that I nees to filter my articles containing blocks (I am not using ajax for research yet).

    Thanks

    Moderator bcworkz

    (@bcworkz)

    Disregard my previous reply, I’ve misunderstood what you are asking. If you want to query for posts with certain block attributes, your only option with WP_Query is to use the text search capability (“s” query var). This can search post content for specific attribute values. If you need something more sophisticated, such as search by regexp, you’ll need to compose your own SQL query and execute it with $wpdb object methods.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Blocks & WP_QUERY’ is closed to new replies.