'How to access wp_query in block pattern
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 -->',
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
