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
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