Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Showing Custom Post type within another custom post type
I've created a few custom post types for my real estate page (i.e. Listings, Agents, & Neighborhoods). I'm having some trouble understanding how to display a specific agent post type within a single listing post type page.
Under my listing post type, I've created a few ACF fields, one being a checkbox or dropdown for agents. When an agent is selected from the checkbox / dropdown menu, I'd like it to recognize, which agent that is and display the information for that agent from the other custom post type of agents. I hope this makes sense.
I'm working in the single-listings.php and have a 2 column layout. The left column will have all the information about the real estate listing, address, pictures, description, etc. The right column, I want to display the agent picture, name, phone, & email based on who was selected when that custom listing was made.
I hope this makes sense!
Since you are using ACF already, I would suggest using ACF's relationship field. This way you will be able to create a relationship between your custom post types. please see the docs below:
To clarify more. I'd like to dynamically populate the information here depending on which agent was checked/selected when creating the listing.
<div class="listings-agent"> <h1>Listing Agent</h1> <img src="<?php this would be php code pulling featured image of selected agent ?>"> <h2><?php this would be php pulling Full Name of agent selected ?></h2> <h3><?php this would be php pulling phone number of agent selected ?></h3> <h3><?php this would be php pulling email of agent selected ?></h3> </div>
Keep in mind, that this information would be pulled from another custom post type other than the current page post type of "listings" that we would be on.