• Resolved jaxtheking

    (@jaxtheking)


    A while ago I realised that post_name in WordPress never changes after a post is created. For instance, updating a post’s title does not update post_name.
    On my site, I needed to have child posts to have a permalink like /parent_name/child_name and started using the %parent_postname% token. However, when I changed the title of a parent and regenerated the permalink for a child, the parent_name part would not update.

    I resolved this issue (been testing this for over 6 months) by creating a new %parent_title% token, which simply uses post titles instead of post names.

    Would you consider adding this to the plugin? Please find the code below (it was duplicated from %parent_postname%):

    // Replace %parent_title% with the respective post title with the
    // parent post title if parent post is selected
    if ( false !== strpos( $replace_tag, "%parent_title%" ) ) {
      $parents = get_ancestors( $post_id, $post->post_type, 'post_type' );
      $posttitles = '';
      if ( $parents && is_array( $parents ) && ! empty( $parents )
        && count( $parents ) >= 1 ) {
        $parent = get_post( $parents[0] );
        $posttitles = sanitize_title( $parent->post_title ) . '/';
      }
    
      $title = sanitize_title( $post->post_title );
      $posttitles .=  $title;
    
      $replace_tag = str_replace( '%parent_title%', $posttitles, $replace_tag );
    }

    Many thanks,
    Luca

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sami Ahmed Siddiqui

    (@sasiddiqui)

    Hi Luca,

    Thanks for reaching out and providing the new tag in plugin…!

    Sure, i will add this tag in the coming release.

    Thank you once again.

    Regards,
    Sami

    Thread Starter jaxtheking

    (@jaxtheking)

    Hi Sami,
    thanks a lot for the quick consideration. Very appreciated it. Very cool plugin BTW.

    Plugin Author Sami Ahmed Siddiqui

    (@sasiddiqui)

    Hi @jaxtheking

    Sorry, I was stuck on a few things and didn’t able to update the plugin. Finally, I got some time now and added the following tags in v2.7.0.

    1. %parent_title%
    2. %all_parents_title%

    Please update to the latest version and don’t forget to provide your valuable feedback to me.

    Thanks,
    Sami

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Possible to add new token %parent_title% ?’ is closed to new replies.