Query Post Type Within Loop

This is something we used to do all the time on CCS, but I can’t see how to do it here. Basically we’re just after the L&L version of:

[if type=my_custom_post_type]

[/if]

For example, if we have something like:

<Loop type=cpt_one,cpt_two,cpt_three>
  <If type="cpt_one">
    Output specific to cpt_one
  <Else />
     Output for when it's not cpt_one
  </If>
</Loop>

I’ve looked through the documentation and seen there’s this:

<If singular type="cpt_one">

But I believe that’s for use on a single post rather than within the loop? Either way I tried it and it didn’t work.

I’m away from my computer at the moment so I can’t test this, but I believe when you’re looping through post types (as you’re doing with <Loop type=x,y,z>) you can display the title field of the post type with <Field title/>. I’d assume in that case that you could also run some conditional logic with <If field=title value=x>. Let me know if that works for you!

And if ever you were trying to do this kind of thing when you’re in a singular post and not looping through post types, you could use <If field=type value=x>.

Let me know if that works for you!

Ah, sorry, it’s not looping through post types. It’s a normal post loop we’re just filtering by multiple CPTs. So it’s about the post type of the specific post within the loop. Ie: <Field title /> would return the title of the post rather than the post type.

I think you may have solved it anyway, I tried this: <If field=type value=x> and it seems to have worked.

So in my original example it comes out as:

<Loop type=cpt_one,cpt_two,cpt_three>
  <If field=type value="cpt_one">
    Output specific to cpt_one
  <Else />
     Output for when it's not cpt_one
  </If>
</Loop>
2 Likes