Custom post types and namespacing


Hello, First of all let me just say that Beans is awesome! Thanks for this beautiful framework.

Second, here's what I'm trying to accomplish. I've created a front-page.php file that has multiple sections in it. Each section will be receiving custom post type queries in them.

After reviewing other discussions in this forum I added a new WP_Query with my custom post type in the $args. However it keeps coming up with an error saying the class WP_Query is not available. I'm using namespacing in my theme. I'm not sure how to add this custom query within Beans.

Any help you can give would be greatly appreciated. Thanks!


Hello Jimmy, Could you please show us the code you use to display these custom queries ? Mat


Hi Jimmy,

To call a class or a function from global namespace inside another namespace, call it with a backslash before. e.g. new \WP_Query();.

BTW to create a custom loop with Beans:

beans_add_filter( 'beans_loop_query_args[_my_custom_loop]', array(
    // new query args here.
) );

beans_loop_template( 'my_custom_loop' );

That worked perfectly. Not sure how I missed this in the doc but thank you for taking the time to reply and help me out. I greatly appreciate it Joseph!

Write a reply

Login or register to write a reply, it's free!