weedor
March 27, 2023, 6:14pm
1
In a query loop with products, I have 2 DIVs.
The firt one is empty
The second one contains a code block with the code below:
<?
global $product;
echo $product->get_id();
?>
The result is ok, but if I remove the first DIV (the empty one) there is an offset of ID and the results goes wrong. The echo returns the product ID of the previous loop.
PS: I regenerated the blocks and all the stuffs.
Environment info
WordPress version: 6.1.1
Gutenberg Plugin version: N/A
Cwicly Plugin version: 1.2.9.5.5
Cwicly Theme version: 1.0.3
weedor
March 27, 2023, 10:25pm
2
Here is a screnshot to show the difference between $product->… and get_the…
Louis
March 28, 2023, 9:05pm
3
Hello @weedor ,
Sorry to hear you’re having trouble accessing the correct product with the Code block.
This does seem rather unusual, but could be a question of some block not transmitting the correct context. I’m currently not able to reproduce this.
Can you possibly let me know the full structure of your query template?
Thanks in advance.
weedor
March 29, 2023, 9:24am
4
Hi @Louis
Here is the context:
The site: hhtps://smatchcard.com
The blank page: test51
The template: Page_tickets
Here is the hierarchy:
Here is the query for products:
Product: Category=Events; Visibility=Visible;
Order: Name=ASC
The code in code block:
<?
global $product;
echo '$product->get_id() = ' . $product->get_id();
echo '$product->get_title() = ' . $product->get_title();
echo 'get_the_id() = ' . get_the_id();
echo 'get_the_title() = ' . get_the_title();
?>
PS: plus some ‘br’ for carriage returns
Here is a message displayed on top of page:
Error: Call to a member function get_id() on boolError: Call to a member function get_id() on bool
And here is the beginning of display:
I hope this will help for debug.
For sure, I can grant you an admin access if you need.
In the other hand, can you publish the whole list of valid tags (or at least an explanation to know what tag is valid or not).
Thank’s @Louis
Cheers