调查render_block_core_post_template()
我们可以看到它在呼叫build_query_vars_from_query_block()
(以前的名称construct_wp_query_args
) 设置的查询参数WP_Query
从“块属性”查询。
从那里我看不到它支持secondaryquery的自定义分类法。。。然而
Work-around-idea: 对于查询循环:
添加用于使用自定义分类法的搜索关键字,例如。
:query-motor-electric
:
并编写一个插件来处理此问题:
// Replace :query-motor-electric search keyword for a custom taxonomy query.
add_action( \'pre_get_posts\', function( \\WP_Query $q ) {
if ( $q->is_search() && \':query-motor-electric\' === trim( $q->get( \'s\' ) ) ) {
// Custom taxonomy query.
$tax_query = array(
array(
\'taxonomy\' => \'motor\',
\'field\' => \'slug\',
\'terms\' => \'electric\',
),
);
$q->set( \'tax_query\', $tax_query );
// Clear search, unset search query variable or use a stop-word filter.
$q->set( \'s\', \'\' );
}
} );
或者进一步扩展它以支持动态关键字。
Example 查询循环的块代码:
<!-- wp:query {"queryId":1,"query":{"perPage":3,"pages":1,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":":query-motor-electric","sticky":""}} -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:post-title /-->
<!-- wp:post-date /-->
<!-- wp:post-excerpt /-->
<!-- /wp:post-template --></div>
<!-- /wp:query -->
相关搜索部分为:
<!-- wp:query {...,"query":{...,"search":":query-motor-electric"}} -->