wordpress - Custom post types permalink with parent custom post type -
hard define title of question....
i want create nice readable permalink construction 2 custom post types (cpt). first cpt "family" has next rewrite-slug "family/%postname%" (all works fine)
the sec cpt "childs" has metabox can select parent_id-field choosing cpt "family" child-cpt belongs to. works great.
now set rewrite-slug "childs" "%parent_post_url%/child/%postname%" can next url "family/the-griffons/child/peter" . when phone call url wordpress displays not-found-page. crazy thing if set rewrite-slug hard "family/the-griffons/child/%postname%" can phone call url (both urls same!!!)
so why toes wp throws error when seek url dynamically not when hardcode url??
the child-parent relationship think have not quite there. based on you've told far, seems have custom field denoting "pseudo-parent" id. question should read is
how rewrite first part of cpt url, based on cpt custom field value ?
because, far wordpress concerned in case, that's "parent id" is- custom field value.
you can seek next last part(part 3.) of this tutorial, keeping in mind, you'll want actual path of url of "parent id" , not cf "parent id" value itself, you'll have implement along lines of:
$parent_id = get_post_meta($post_id, "your_cf_key_for_parent_id", true); $full_parent_post_url = parse_url( get_permalink( $parent_id ) ); $parent_post_url = $full_parent_post_url['path']; if(!$parent_post_url) { $parent_post_url = "default-fallback" } $permalink = str_replace(‘%parent_post_url%’, $parent_post_url, $permalink); homecoming $permalink;
another relevant stackexchange answer:
using-custom-fields-in-custom-post-type-url
but @c0ns0l3 mentioned using custom taxonomies proper way go this.
wordpress custom-post-type permalinks
No comments:
Post a Comment