We use Beaver for all our clients to create smart E-Commerce drag and drop feature using the power of Beaver.
With the last update, seemingly you changed the logic of getting the current post ID and thus all of our clients are now broken, all of them.
Fixed a bug with getting the correct ID for the current post.
What we used to do is simple, we have a static page template (page created with Beaver, let’s assume its ID=40) and for pages with a certain meta option (e.g. “load_template_instead” set to true) we load the page 40 instead of it.
And this is the ‘fl_builder_global_posts’ hook in order to load styling of page 40:
public function wc_product_page_load_fl_template( $post_ids ) {
if ( !Helper::load_template_instead() )
return $post_ids;
$post_ids[] = 40;
return $post_ids;
}
All we want to do is to load a static Beaver page instead of the current one.
The way we did it above, FLBuilder::render_content following line was equal to 40
$post_id = FLBuilderModel::get_post_id();
But now it is the POST_ID of the current page, thus rending the wrong content.
Note, we don’t use secondary loops because there are global variables that might be lost (e.g. global $product of WooCommerce plugin).
What can we do in order to solve this issue and make rending custom page an option?
This is our bread and butter and thus why we have been working with Beaver for a long time.
Sorry for the issues. We had to change the logic of FLBuilderModel::get_post_id as it is intended to return the post ID for the current post in the main loop. Secondary loops that weren’t correctly resetting the global post data were breaking the builder, so we made the change to fix that.
I’m not quite understanding where your issue is, can you elaborate on what exactly isn’t working? Is it your wc_product_page_load_fl_template function? Or do you need FLBuilderModel::get_post_id to return the post ID of your template?
I need FLBuilderModel::get_post_id to return my template ID. Exactly.
See my comment below.
// Get a post ID sent in an AJAX request.
if ( isset( $post_data['post_id'] ) ) {
return $post_data['post_id'];
}
// Get a post ID from the main query.
// ** THIS NEW CONDITION IS NOW TRUE THUS RETURNING THE "REAL" ID **
else if ( in_the_loop() && is_main_query() && isset( $wp_the_query->post ) ) {
return $wp_the_query->post->ID;
}
// Get a post ID in a query outside of the main loop.
else if ( isset( $post ) ) {
return $post->ID;
}
Just in case your solutions (that look neater tbh) fail, what are the main usage of the following condition:
The $post_data array is set either by the $_POST[‘fl_builder_data’] JSON sent via AJAX, or by the $_POST array itself. You can see that in FLBuilderModel::get_post_data.
What are the risks?
It’s hard to say if there are any. Give it a shot and let me know how it goes.