Mixed post_type in a loop

Hi,

I need to make a loop to output a list of posts from mixed posts types and ordered them by date.

I tried this
<Loop type=post,mec-events count=8 order_by=date order=desc>
but it does not mix the posts.
Here is what I got :
post 1, post 2, post 3, event 1, event 2, event 3
but I want this :
post 1, event 1, post 2, event 2, event 3, post 3

I tried this
<Set name=newsfeed> <Loop type=post,mec-events count=8 order_by=date order=desc> <Field id />, </Loop> </Set> <Loop id={Get name=newsfeed}> <div class="af_post"><Field title /></div> </Loop>

but I does not work either.

Any idea to make this works ?
Best

Hi Guillaume,

This actually works as expected for me, after correcting the orderby parameter to remove the underscore:

<Loop type=post,mec-events count=8 orderby=date order=desc>
  <div class="af_post">
    <Field title />
  </div>
</Loop>

Does it work for you?

1 Like

Oh yes ! You’re right, thanks a lot Julia :+1:

So, loops with mixed post types are officially supported?

I tried this the other day with standard posts and a custom post type called gallery but I don’t think I got it working.

I don’t think the docs mention this feature. :thinking:

Actually it works in my case with posts, custom post types and mec-events (Webnus plugin). +1 for the documentation

2 Likes

Good call! I’ve added a mention on the Loop and Loop type: Post documentation pages

2 Likes

Thanks, @julia.

My previous attempt failed because there seems to be an issue when combining multiple post types with the terms tag in a loop config.

This loop works:

<!--Posts loop-->
<Loop type="post,gallery" taxonomy="category,gallery_category">
    <Field title />
</Loop>

But this loop does not:

<!--Posts loop-->
<Loop type="post,gallery" taxonomy="category,gallery_category" terms="news,writing,music">
    <Field title />
</Loop>

I wonder if defining each taxonomy separately would help?

<!--Posts loop-->
<Loop type="post,gallery" taxonomy="category" terms="news,writing,music" taxonomy_relation="or" taxonomy_2="gallery_category" terms_2="news,writing,music">
    <Field title />
</Loop>

Thanks but this returns only the first post type and taxonomies.

Test loop:

<!--Posts loop-->
<Loop type="post,gallery" taxonomy="category" terms="news,writing" taxonomy_relation="or" taxonomy_2="gallery_category" terms_2="paintings,exhibitions">
    <Field title />
</Loop>

Weird! We may need to modify how the taxonomy and term parameters behave when a loop has multiple post types

1 Like

I meant to follow up on this thread earlier but I lost track of it. When I started learning L&L, this took me a while to realize because I was skimming over the docs but this information has actually always existed in the docs, although it’s easy to miss it. I’m not sure if this is universally consistent throughout the docs but it’s definitely mentioned in relation to query parameters. If you check out any list of query parameters, you’ll see that each parameter has a “type” written underneath it, which mentions the types of data that are accepted. For example, on the post loop page of the docs, the author attribute mentions that the type of data it accepts is “Type: string, array.” An array is just a fancy word for a list, so this is how you know that this parameter accepts multiple values. Same for a lot of the other parameters, including the type parameter.

Most attributes and query parameters in the docs specifically mention when they accept an array in their value, so I thought I’d clarify that since this doesn’t just apply to the type attribute.

I think the actual fix that needs to be made to the docs is that we need a section in the getting started guide that explains some of these terms to people who are coming from a purely HTML background and might not be familiar with them. We already have a section of the docs dedicated to terminology but I feel like most people won’t find that and will just skim over mentions of strings and arrays if they don’t know what that means. And maybe we could also change mentions of “Type: string, array” to instead say “Accepts value of type: string, array” although that might be a big undertaking to change all of that. I’ll at least work on adding a note to the getting started section to clarify this for all parameters moving forward instead of having a one-off mention of the type parameter in the docs since that makes it seem like the type attribute is unique in this way.

2 Likes

Thanks for the update, from my point of view, a short docs section on advanced loops with multiple post types and taxonomies/terms would be fine.

1 Like