[Content Hidden]
Hey Marc,
Thanks for sharing, I’ve just replaced the code mentioned above. Let us know if you need anything further.
Thanks!
KC
Hey Marc,
The issue is that you’re using apply_filters instead of a loop. I believe you can use setup_postdata to set the global post variables so your previous loop will work with get_posts. Give that a shot and let me know how it goes.
Justin
Howdy Justin,
I just wanted to update you on my findings. I wasn’t able to make use of setup_postdata, but I got everything to work now. There was one very important detail that took me almost a full days work to figure out. The filter: “the_content” works, but only if the variable that holds the post object is actually called: “$post”. Anything else and the filter fails.
Thanks again for your help,
Marc
Hi again. Another issue I just discovered is that a non-public post-type isn’t showing up on BB’s options page > post types. Thanks.
Hey Marc,
I believe the issue with non-public post types is that the builder won’t work on them since they can’t be viewed on the frontend. Also, if we did show non-public post types, things like Revisions and Navigation Menu Items would show up in that list.
Would you mind testing out your use case for me? That can be done by changing line 44 of includes/admin-settings-post-types.php from this…
$post_types = get_post_types(array('public' => true), 'objects');
to this…
$post_types = get_post_types(array(), 'objects');
Let me know how that goes.
Justin
Hi Justin,
Remember how I wanted my components post-type to be hidden from the search results. I’d also like it to be hidden it from the Posts Module. As I mentioned above, I’m having ‘publicly_queryable’
& ‘query_var’,
set to true
which enables my components type to be working on the frontend, even with ‘public’
set to false
. However, it’s hidden from the Posts Module, which I prefer.
I think it’s better to hide this type of post-type from the end user rather than the admins who are responsible for managing BB’s options.
Why not use the below snippet (which works on my end) on line 44 in includes/admin-settings-post-type.php and let the admins decide which post types the builder should work on?
$post_types = get_post_types( array(), 'objects' );
unset($post_types['revision']);
unset($post_types['nav_menu_item']);
Hey Marc,
My worry there is that different plugins might register a number of different post types that you wouldn’t want showing up. We can unset revision and nav_menu_item, but we can’t account for any of the others. For example, when I activate WooCommerce, I get Variations, Orders, Refunds, Coupons and Webhooks.
Maybe a filter would help? Let me know what you think.
Justin
Hey Justin,
Yep, a filter makes perfect sense here. I’ll let you know should I encounter any other issues.
Thanks again.
Marc
Hi Justin,
I think it’d also be nice to be able to remove post types from the settings page.
For example, blog posts are pretty repetitive and using a component post type as a template for the posts would be more efficient than having to BB build each post from scratch.
In such a scenario, I would want to disable the option to use BB on posts. Another reason would be to be able to exclude any other post types that shouldn’t be there but found their way into the settings anyhow.
What do you think?
Marc
Hey Marc,
Unfortunately, without that setting, there would be no easy way to enable BB on different post types. Everyone has different needs and some people do use it on posts, so we’d like to leave that setting for them. You could probably hide it with a little CSS via a small plugin.
Justin
Justin, Sorry, I meant to say “remove individual post types from the settings page” not the whole thing. Since the filter you mentioned here would enable theme authors to add types that wouldn’t normally show up, I thought that it could also be beneficial to theme authors to remove types for the before mentioned reasons.
Right on, Marc. Thanks for the clarification. Let me see what I can do with a filter. Checking that out now…
Hey Marc,
I just changed this…
$post_types = get_post_types( array( 'public' => true ), 'objects' );
to this…
$post_types = get_post_types( array( 'public' => true ), 'objects' );
$post_types = apply_filters( 'fl_builder_admin_settings_post_types', $post_types );
The fl_builder_admin_settings_post_types filter will now let you modify what objects are included in the $post_types array. Let me know if you have any questions about that. This filter will be included in the next minor release.
Justin
Howdy Justin,
I’m using the filter like this:
/**
* Add non-public post types to BB's option page.
*/
add_filter( 'fl_builder_admin_settings_post_types', 'add_nonpublic_type_to_bb_settings' );
function add_nonpublic_type_to_bb_settings( $post_types )
{
$type_slug = 'components';
$type_obj = get_post_type_object( $type_slug );
$post_types[ $type_slug ] = $type_obj;
return $post_types;
}
Hopefully, this will save you some time writing the documentation.
Thanks for the filter!
Thanks, Marc! That’s exactly how it should be done. I’ll definitely use that example