I’m trying to override the current post in the loop.
For example:
global $post
$post = get_post_id(1); // some post id - predefined page
setup_postdata( $post );
I want to “cheat” Beaver (the whole WP) and make it render the post_id provided above (in the example id=1) with the layout scripts of post_id=1 that are added by:
add_action(‘wp_enqueue_scripts’, ‘FLBuilder::layout_styles_scripts’);
add_action(‘wp_enqueue_scripts’, ‘FLBuilder::styles_scripts’);
Beaver will render post=1 but when rendering the modules.
The custom modules have an indication of which data to render dynamically.
This is necessary for a problem I am trying to solve.
How do I achieve this?
I tried the following:
function set_page_template() {
global $post;
$post = get_post( 1 );
setup_postdata( $post );
}
add_action('init', 'set_page_template');
But still, Beaver renders different POST_ID_layout.css
<link rel=‘stylesheet’ id=‘fl-builder-layout-289-css’ href=’…/wp-content/uploads/bb-plugin/cache/289-layout.css?ver=98a27aba73f876ddbe794159c49fe08c’ type=‘text/css’ media=‘all’ />
It feels to me that I need to override $wp_query at early stages because the GLOBALS[‘post’] is initialized using the value of $wp_query as in the following diagram:
Telling me how WooCommerce handles the get parameter ?product=my_product to determine the active page would help or give ideas. I cannot find out how WC does that.
I printed the $query object inside the action. I understand that the system creates a query that depends on the URL. Now I am looking on how to override the current post. After calling it with high priority, and try to print $query, this is what I get.
Now I want to alter the current post to another predefined one (e.g. post with ID=1)
It would be great if there is a way to do that without affecting WC globals, but that’s easy to solve.
I know it is now out of Beaver scope, but would be great if you provide assistance.
This is important for my Beaver because I am planning to make WooCommerce pages using Beaver D&D.
Unfortunately, this is beyond the scope of the support we offer here as I would really need to spend a significant amount of time researching and writing code for you to get this to work.
I don’t mind pointing people in the right direction for help with custom code, but in this case, you are trying to do something that I’m not really that familiar with.
I can tell you that the builder uses the post ID that is either provided in the global $post variable, or in data that is sent to the server while you are working on a page. You can see that in FLBuilderModel::get_post_id(). The method get_asset_info uses that same post ID, so it does sound like you’re still not completely overriding it.
I would do some research on overriding the main query using pre_get_posts as from the brief reading I did, it sounds like that’s what you need.