Skip Navigation

[Closed] 2 custom post types. Can one be the parent of the other and display breadcrumbs

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 11 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Caridad 11 years, 3 months ago.

Assisted by: Caridad.

Author
Posts
#34511

Hi there,

I have a problem that is driving me crazy. I have 2 custom post types:

1.) City Information
2.) Local Areas Information

I want the City Information to display independently, with a link to the "child" CPT local areas.

I would like the breadcrumb to look something like this:

HOME > CITYNAME > Local Area

Now, the problem lies exactly here. The Yoast SEO plugin or the the breadcrumbs XT plugin doen't accept a relationship between 2 CPT it seems, so there is no way I can make the Local Area CPT the child of the City CPT.

This is where I stand now.

However I still have to display the content hierarchically like in posts.

With posts it is easy, as they have the exact same data fields, i.e. Title and Content.

For my 2 CPT, there are different custom fields specified, such as:

City Name
City Information
City other details

Local Area Name
Local Area picture
Local Area link

Therefore I am struggling with "merging" the 2 CPT into a single CPT, as I would lose the ability to have children with different "Views templates"...

Is there any idea anybody has to display content in a hierarchical way that makes sense?

Thanks so much!
sanny

#34778

Dear Sanny,

The parent / child relationship set in Types is unique to Types and other plugins wont understand it. I have been testing with WordPress SEO breadcrumbs and came up with this solution. These lines can be added to functions.php in your theme:

add_filter('wpseo_breadcrumb_links', 'add_my_ancestors');
function add_my_ancestors($links) {
	if (get_post_type() == 'employee') {
		$parent = get_post_meta(get_the_ID(), '_wpcf_belongs_company_id', true);
		array_splice($links, sizeof($links) - 1, 0, array(array('id' => $parent)));
	}
	return $links;
}

The code will detect when we are in an employee page and insert a link to the parent company in the breadcrumb.
You will have to replace the strings company and employee with your parent and child slugs.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

The topic ‘[Closed] 2 custom post types. Can one be the parent of the other and display breadcrumbs’ is closed to new replies.