SOLVED: How to output all posts from current (custom) post type in Query Loop on template that applies to multiple CPTs

I solved this using a guide from David Browne over at BricksLabs: Adding any Custom WP_Query loop to Bricks’ Query Loop – BricksLabs

I adjusted the custom query arguments to the following:

     /* Add all of your WP_Query arguments here */

    $args = [ 
        'post_type' => get_post_type(),
        'orderby' => 'menu_order', 
        'order' => 'ASC', 
        'posts_per_page' => '50',
    ];

Original question below:
Hi gang. I need a little help with a Query Loop query.

I’ve got a basic page template with a sidebar. This template applies to multiple custom post types (default “page”, “service”, “training”, “product”).

I’d like to include a list of all other posts in that post type in the sidebar, generated dynamically based on what CPT that post happens to be in.

For example, the Query Loop list displaying on a “Service” post type will display all the other “Service” posts. The same Query Loop displaying on a “Product” post type will display all other “Product” posts, etc.

I could tackle this simply by having multiple page templates — one for each CPT — and then having a basic Query Loop that queries posts from that CPT. Or I could have duplicated Query Loops displayed conditonally based on the post type. But I want to try to have just one template, and just one Query Loop.

Any thoughts on how to configure my query to pull this off? I imagine it’s pretty simple and something’s just not clicking for me that should be.

1 Like