如何以块模式访问wp_query
我想创建一个高级的“ Next /上一篇文章”块模式(带有标题,功能映像等),它已注册并显示在FullSiteEditor中。
但是,我无法获得当前的帖子对象 /查询。可能是因为在INIT上注册了块模式。所以查询还不可用吗?任何解决此问题的想法都将不胜感激。
简化的代码是:
$works_1 = get_template();
$works_4 = get_site_url();
global $post;
global $wp_query;
$works_not_1 = get_the_ID();
$works_not_2 = get_post($post);
$works_not_3 = $post->ID; // Throws ERROR
$works_not_4 = $wp_query->post->ID; // Throws ERROR
$works_not_5 = get_page_uri($post);
$works_not_5 = get_the_title();
return array(
'title' => __('das nächste projekt', 'tttstarter'),
'categories' => array('pages'),
'content' => '<!-- wp:paragraph --><p>' . esc_html($works_not_3) . '</p><!-- /wp:paragraph -->',
);
I want to create an advanced "next / previous post" block pattern (with title, feature image, etc. ) It' registered and shows up in the FullSiteEditor.
However I can't get the current post object / query. Probably because block patterns are registered at init. So the query is not available yet?! Any ideas how to solve this would be very appreciated.
Simplified Code is:
$works_1 = get_template();
$works_4 = get_site_url();
global $post;
global $wp_query;
$works_not_1 = get_the_ID();
$works_not_2 = get_post($post);
$works_not_3 = $post->ID; // Throws ERROR
$works_not_4 = $wp_query->post->ID; // Throws ERROR
$works_not_5 = get_page_uri($post);
$works_not_5 = get_the_title();
return array(
'title' => __('das nächste projekt', 'tttstarter'),
'categories' => array('pages'),
'content' => '<!-- wp:paragraph --><p>' . esc_html($works_not_3) . '</p><!-- /wp:paragraph -->',
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于需要黑客攻击的任何人,我都会使用这个:
For anyone that needs a hack for this, I use this one: