I’m trying to use the Templates posts in place of headers and footers. I’m using the get_post() function, which kind of works. The function returns the HTML of the template, but not the CSS styles. Could anyone enlighten me how to do this properly?
Thanks for the heads up. If have been trying to figure this out for the last couple of hours but no luck. The best I could do as of now is to modify the main query and reset it again to get the complete HTML code of the template. However, it seams that the specific CSS for the template is not being loaded along with it.
query_posts( array(
'post_type' => 'fl-builder-template',
'post_status' => 'any',
'p' => 68, // post id
) );
while (have_posts()) : the_post();
the_content();
endwhile;
wp_reset_query();
The issue is most likely that the CSS/JS for the layout your are rendering via a secondary loop isn’t being loaded. Have a look at the fl_builder_global_posts filter to fix that…
Thanks for helping out. Sorry though, the filter doesn’t make a difference. The snippet I posted above is living in my header.php and I tried use the filter you mentioned inside the functions.php file.
BB is enqueuing the stylesheet for the respective page ID, but I can’t find the node-id inside of it and there is also no other stylesheet for the fl-builder-template being enqueued.
I tried clearing my browser’s and BB’s cache but it didn’t solve my problem either.
Would it be possible for you to share temp admin access to the site so we can take a look? You can just post the details here using the private reply option below.
It seems we’re having issues with the filter when used on templates. I’ve filed a bug report so our lead dev can check. Thanks for the heads up! For now, you can just use a page or post instead of a template.
A fix for this issue will be available in the minor update next week. For now, you can patch it if you would like by making a change to classes/class-fl-builder.php. Just add the following code after line 369 in the layout_styles_scripts method and it should start working…
// Enqueue assets for templates since they won't be returned in the query above.
$posts = get_posts(array(
'post__in' => $post_ids,
'post_type' => 'fl-builder-template',
'posts_per_page' => -1
));
foreach($posts as $post) {
self::enqueue_layout_styles_scripts($post->ID);
}
NOTE: I posted the following before refreshing the page. Thank you Justin. I’ll try that and I’m looking forward to the update. You guys rock!
Thanks for passing it on Ben. I tried the using the “page” post_type inside of the query_posts() as mentioned above, but it’s also not working as expected. Am I doing it wrong? If not, maybe update your bug report accordingly. Thanks again for your support.
Justin, will the update enable the use of other post types as well? For example, if I were to register a post type called “Components” that I wanted to use instead of the “fl-builder-template” post type. Would that also work?
Hey Justin, I was pretty tired when I posted my previous reply to you. To clarify my question; I would not want my “components” post-type to show up in the search results. However, the function get_posts( ‘post_type’ => ‘any’ ) on line 363 inside FLBuilder::layout_styles_scripts() function will only get types that have the parameter “exclude_from_search” NOT set to true. I think such a post-type should not belong inside the search results and this could be solved better. Thanks.
Not having the post types show up in search is the issue as post_type => any won’t return them. That’s why I’m doing an additional query of post_type => fl-builder-template, but I didn’t think about other post types that aren’t included in search.
Let me chew on this one a bit more and get back to you.
I did some more testing and found a solution that should work in all cases without the need to do anything additional. First, scrap the code I gave you previously. Then, within that same class, change this…
Now, the only other thing on my mind is the poor performance of query_posts(). From the codex: “It is inefficient (re-runs SQL queries) and will outright fail in some circumstances…” Any ideas or plans?
Regarding, query_posts, we’re actually using get_posts which I believe doesn’t alter the main query or have the same issues as query_posts. You could try running get_posts in your code as well, it should work.
Thanks yeah it’s working. The first time I tried I forgot to run it through “the_content” filter. I posted the code below in case others find themselves here. Thanks again for all your help.