Segment Search Results by post type

For my search results template, I want to test for the Custom Post type of each result. e.g.

[wpbb-if CUSTOMPOSTTYPE exp='equals' value='Cats']
  Print Cats
[wpbb-if CUSTOMPOSTTYPE exp='equals' value='Dogs']
  Print Dogs

How can I do that?

Cheers, Richard

Hi there,

I think these pages will help you.

there is no way for the wpp-if shortcode to check the post type.

You might need to create your own shortcode to check the post type and print animals.

I suspected as much. I have a number of post types that should be displayed differently, so I added an ACF text field to each called xx_type. Then I’m using a snippet to automatically fill in that field with the post type e.g. “Dogs” or “Cats” triggered by acf/save_post.

In the Search Results template, I have a posts module with a Custom Post Layout that looks like this:

[wpbb-if post:custom_field key='xx_type' exp='equals' value='Dogs']
[wpbb-if post:custom_field key='xx_type' exp='equals' value='Cats']

It works if that helps anyone else, but I’d be happy to hear any better ideas.

Cheers, Richard