I’m loading some bricksbuilder template via ajax, however it doesn’t seem to be possible to pass the template ID directly:
$template_content = do_shortcode("[bricks_template id='{$template_id}'
My workaround is to use global post (which i don’t like)
Is there a way to pass the Id directly in the short code?
This is not working:
$post_id = intval($_POST['post_id']);
$template_id = '1073'; // Template ID
$template_content = do_shortcode("[bricks_template id='{$template_id}' post_id='{$post_id}']");
I need to temporarily set a global post variable
$post_id = intval($_POST['post_id']);
// Save the current post object
global $post;
$original_post = $post;
// Set the global post to the requested post ID
$post = get_post($post_id);
setup_postdata($post);
// Render the BricksBuilder template
$template_id = '1073'; // Template ID
$template_content = do_shortcode("[bricks_template id='{$template_id}']");
// Restore the original post object
wp_reset_postdata();