Multiple post types in one Query Loop?

Hi, I’m wondering is there a known trick to combine somehow results from 2 different post types into one Query Loop (like from the WP Posts + one CPT called “Publication”)?

Hi, I was writing to ask something similar ^^
I also need the GB Query Loop Block be able to fetch multiple post types ?! eg screen below :


Hi, this sounds promising but how to actually present (choose somehow) these in one certain Query Loop on a specific page?

You can specify which Query Loop it applies to be selecting the Query Loop > Grid Block and in Advanced > Additional CSS Class(es) add : my-query which is the class you specify in this line of the code:

strpos( $attributes['className'], 'my-query' ) !== false

Hi, thanks, this seems to work fine with (WP-core) pages & posts but not any CPT. in this case I would like to combine WP-posts + custom post type named ”publication”. If trying to do so, it shows only posts. Any further ideas what could cause this? Have used CPT UI to put up the CPT’s, settings ”should be fine” there…

1 Like

I need this feature as well. Same problem, not working with Custom Post Types.

Hi @joeldeteves,

See here for reference: Multiple Post Types in Query Loop

Thanks @fernandoazarcon2 I did in fact try that code using the cpt but it did not work for the cpt.

Same issue as @Kirmo

Can you check if the CPT is Publicly Queryable? Try setting it to true if not.

It does appear to be working now as expected. I must have fat fingered something late last night.

Thanks David and Fernando for the quick solution.

Now, I have another question:

I need to filter all posts with a specific tag, but allow all custom posts without any tag. Is this possible using this code?

Hi, this code is working fine with multiple CPT’s but if some (or one) of them is WP’s core post types (even ”post” or ”page”) then it is not working anymore like wanted. In that case Query Loop is only showing the ”core content”. I would like to show both ”post” and (CPT) ”publication” together in one Query Loop. My CPT’s are also set to Publicly Queryable.

Well, this really seems to work in a normal single WP installation with exactly same CPT’s. The site where it wasn’t working is a part of the multisite installation > something is different there what comes to CPTUI plugin and it’s behaviour in custom post types(?)

Just a note here, the CPT must be enabled in the REST API to work properly on the editor.
Registering A Custom Post Type With REST API Support

Also, posts from different sites/blogs (WP multisite) do not work, you can’t combine posts from 2 different sites.

Hi, yes thanks. I was actually here on this particular site combining posts from the same wp-site (though it is part of the multisite installation). And at least in this (Bitnami) stacked multisite this causes problems when other of the type of combined posts is even Post or Page (from WP core).