default post hierarchy URL rewrite
-
Hi there!
I’m having a heckuva time sorting out how to do this. I spent the better part of yesterday and today looking for a straightforward solution… but… here I am.
OK… here’s my goal:
I want to have the ability to choose a parent post (for the default ‘post’ post type) AND have the parent slug show up in the Permalink URL. Know what I’m saying?
For example:
>> Say, I have a post called: My Parent Post
>>>> The URL, based on my Permalinks setup is something like: https://www.example.com/my-parent-post/>> Now, I create a child post, and call it: My Child Post (and *attach* it to the aforementioned Parent)
>>>> I want the URL for it to be something like: https://www.example.com/my-parent-post/my-child-post/ rather than simply: https://www.example.com/my-child-post/It feels like an easy thing, but then my mind gets weird when I see Regular Expressions, and then I nap underneath my desk for a long time.
So far, I was able to accomplish the first part (making the post type ‘post’ hierarchical and creating the box in the Post Editor to select a Parent), by using the following code:
function my_hierarchical_posts($post_type) { if ($post_type != 'post') { return; } global $wp_post_types; $wp_post_types['post']->hierarchical = 1; add_post_type_support( 'post', 'page-attributes' ); } add_action('registered_post_type', 'my_hierarchical_posts', 10, 1 );
Please understand that I do not want to:
- Use Pages instead
- Use a Custom Post Type
- Nor, do I want any taxonomy slugs in the URL
Thanks in advance!
I’m going to contribute in the Forums here now for good Karma.
Have a good one, and Happy Holidays to you! ??
- The topic ‘default post hierarchy URL rewrite’ is closed to new replies.