Skip Navigation

Post ID problem for a custom block within a Toolset view in the block editor

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 voice and has 0 replies.

Author
Posts
#2865682

Hi there,

I built a custom dynamic block that calls the WordPress PHP function get_the_ID() in render.php. The custom block works fine on the public face of the site. When the custom block is inserted into a view created via the block editor, however, it doesn't work correctly. The reason is that get_the_ID() returns the ID of the current View, not the ID of the post in the view's loop.

My short-term solution is to identify the post type of the given ID and ignore the post type "view-template" (and "revision," another post type the block editor uses). Does Toolset recommended another approach to handle this? How can I obtain the "correct" post ID?

Thank you.

Saul