php – How to make posts_like_dislike reference current post when iterating?

Question

I am using plugin https://wordpress.org/plugins/posts-like-dislike/ . It adds a [posts_like_dislike] shortcode. When inside the default wordpress Twenty Twenty-Three in posts “Blog Home” view in here:

<!-- wp:query {"queryId":0,"query":{"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"perPage":10},"align":"wide","layout":{"type":"constrained"}} -->
<div class="wp-block-query alignwide"><!-- wp:post-template {"align":"wide","layout":{"type":"default","columnCount":3}} -->
<!-- wp:columns -->
<!-- wp:column -->
<!-- wp:shortcode -->
[posts_like_dislike]
<!-- /wp:shortcode -->
<!-- /wp:column -->
<!-- /wp:columns -->
<!-- /wp:query -->

It “works”, but it always references the first post. It is because $post global variable inside some wp:query is set to the first post.

This is how the plugin gets the post id. In comparison, the core/ blocks use this code that they receive a $block parameter to WP_Block from render_callback from register_block_type_from_metadata.

How can I access current post ID from inside a shortcode inside wp:query? How can I access current WP_Block $block from inside shortcode or from php? Is there anything else I can try?

I tried doing a lot of research, I tried <?php echo(get_the_ID()); echo(get_post()) but it all references $post which is always the first post only. What is not right?

0
KamilCuk 3 months 2023-09-09T16:36:02-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse