Skip Navigation

[Resolved] Listing two different custom post types in a single view

This thread is resolved. Here is a description of the problem and solution.

Problem:

I am trying to create a combined listing with the union of both post types, a custom field belongs to two different field groups / post types. Should I just include both of them in the Loop Wizard and use conditional tags in the Content Template to avoid empty areas?

Solution:

The specific field can be used with multiple post types, if the custom image field "thumbnail" are using the same field slug, then you just need one Types field shortcode.

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/functions/#image

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#915505
student-work-index.png

Tell us what you are trying to do? I have two custom post types: a Student Project and Student Thesis. I'd like to create a view that displays a grid / index of all Student Project and Student Thesis posts. I understand how to create a single indexical listing of just one post type, but two is out of my grasp. In mathematical terms, I am trying to create a combined listing with the union of both post types, and order them based on a shared field.

Is there any documentation that you are following? No.

Is there a similar example that we can see? Please refer to student-work-index.png.

What is the link to your site? hidden link

#915599

Hello,

Please elaborate the question with more details:
but two is out of my grasp

You can create view, to query posts in both post type: "Project" and "Thesis".

For example, you can create a post view, in section "Content Selection" choose both post type: "Project" and "Thesis".

Why do you think it is out of your grasp?

#915990
loop-wizard.png

Luo, thanks for your reply.

I think the place I'm hung up on is in the Loop Wizard. I know that the Post Title can be displayed in the loop (WP will pull the post title from both custom page types), but I want to also show a field named Index Thumbnail. See attached screenshot. This field belongs to two different field groups / post types. Should I just include both of them in the Loop Wizard and use conditional tags in the Content Template to avoid empty areas?

Here's some pseudo code demonstrating my proposal:

[post title and url]
<if there's a project thumbnail>[project thumbnail]</if>
<if there's a thesis thumbnail>[thesis thumbnail]</if>

(I don't understand how to reference a field inside a view that isn't shared between two different custom posts.)

#916086

If the custom image field "thumbnail" are using the same field slug, then you just need one Types field shortcode:
https://toolset.com/documentation/customizing-sites-using-php/functions/#image

If they are using different field slug, then you need to display it with different shortcode, and you can use wpv-conditional shortcode to check the post type of current post, then display different content, see similar thread here"
https://toolset.com/forums/topic/what-is-the-correct-syntax-to-conditionally-display-based-on-wpv-post-type/

#916408

This makes sense. For some reason I thought that fields were specific to the custom post types, but a given field can be used with multiple post types.

Thank you, Luo! This solved my issue. 🙂

#916423

You are welcome