Ecommerce Shopify WordPress Discussion

How to query posts of certain category in WordPress 6 Block Theme?

I specified category id as follows, but still query all posts, not posts in category 4 (term_id). <!-- wp:query {"query":{"category":4,"perPage":0,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} --> <!-- wp:post-template --> <!-- wp:post-title {"isLink":true} /--> <!-- /wp:post-template --> <!-- /wp:query -->
Firstly, go to visual mode in the WP block editor. Select Query loop block in the editor In inspector control (on the right side of text editor) select Block panel Under Block panel, go to Filters (click the + icon) Select Taxonomies option, then type the desired category name Make sure now the query loop only shows the filtered posts Now turn the editor mode to code editor, you will see the taxQuery like this <!-- wp:query { ... "taxQuery":{"category":[23]}}} --> Source from Gutenberg: https://github.com/WordPress/gutenberg/blob/v17.5.1/packages/block-library/src/post-template/edit.js#L89 Function which build WP_Query arguments from the block's JSON data: https://developer.wordpress.org/reference/functions/build_query_vars_from_query_block/ tax_query array formation from block's attribute query.taxQuery: https://github.com/WordPress/wordpress-develop/blob/6.4/src/wp-includes/blocks.php#L1764-L1775 Snippet: if ( ! empty( $block->context['query']['taxQuery'] ) ) { $query['tax_query'] = array(); foreach ( $block->context['query']['taxQuery'] as $taxonomy => $terms ) { if ( is_taxonomy_viewable( $taxonomy ) && ! empty( $terms ) ) { $query['tax_query'][] = array( 'taxonomy' => $taxonomy, 'terms' => array_filter( array_map( 'intval', $terms ) ), 'include_children' => false, ); } } }

January 27, 2024

thx, i fix it using: <!-- wp:query {"query": {"categoryIds": [4], "perPage": 0, "pages": 0, "offset": 0, "postType": "post", "order": "ASC", "orderBy": "date"}} --> <!-- wp:post-template --> <!-- wp:post-title {"isLink": true} /--> <!-- /wp:post-template --> <!-- /wp:query -->

January 27, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.