如何在自定义Gutenberg块或短代码中重复使用页面查询?
我想解决这个问题,但不确定是否有可能...
说我有一个页面上显示一些术语的页面,所以我开始检索它们:
$children_terms = get_terms(array(
'taxonomy' => $taxonomy_name,
'hide_empty' => false,
'parent' => $related_product_term->term_id
));
很棒。然后,我启动post_content Output,即普通的Gutenberg块。
在Gutenberg的页面内容中间,我需要再次显示上述术语,例如带有拇指和标题的卡片。我可以通过短代码或自定义块进行操作,但是问题在于,在这一点上,我将重复上述查询,这是我在页面模板中已经进行的。
有没有一种方法可以简单地在自定义块或短代码上重复使用$ childris_terms
?
或者,甚至更不可能:有没有办法将Gutenberg输出分为2件,以便我可以在中间放置标准的“手动”代码?
I'd like to solve this problem, but not sure if it's even possible...
Say I've got a page which on header shows some terms, so I start retrieving them:
$children_terms = get_terms(array(
'taxonomy' => $taxonomy_name,
'hide_empty' => false,
'parent' => $related_product_term->term_id
));
Great. Then I start post_content output, which is plain gutenberg blocks.
In the middle of the page contents from gutenberg, I would need to show again the above terms, like cards with thumb and title. I can do it via shortcode or custom block, but the problem is that at this point, I'm going to repeat the above query, which I already did in page template.
Is there a way to simply reuse $children_terms
on the custom block or shortcode?
Or, even more impossible: is there a way to split gutenberg output in 2 pieces, so that I can place standard 'manual' code in the middle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找不到通过页面的任何方法(
$ childres_terms
,请参见上文)变量到Gutenberg的短代码。但是我用“空”解决(我的意思是:没有自定义字段)ACF块,并通过set_query_var
(wordpress api函数)从页面模板中传递$ childres_terms
。I didn't find any way to pass page (
$children_terms
, see above) variables to a shortcode from gutenberg. But I solved with an 'empty' (where I mean: with no custom fields) acf block and passing$children_terms
from the page template withset_query_var
, a wordpress api function.