• supertester

    (@supertester)


    Hi all,

    I need a specific permalink structure for a custom post type.
    This is the structure: /%custom_taxonomy%/%postname%/%subpage%/

    So in example this would be: /ferrari/f430/ as main information page and /ferrari/f430/specs/ or /ferrari/f430/speed/ as subpages.

    The subpages don’t need post edit screens in the backend, it’s database generated.

    How would you archieve this?

    My current solution uses custom permastructs in combination with the post_type_link filter. I then use Endpoints in combination with the single_template filter for the subpages.

    $permalink = '%cars_slug%/%brands%/%cars%/';
    $wp_rewrite->add_rewrite_tag( '%cars_slug%', '(cars)','post_type=cars&slug=' );
    $wp_rewrite->add_rewrite_tag( "%brands%", '(.+?)', "brands=" );
    $permalink = trim($permalink, "/" );
    $rewrite_args = $args->rewrite;
    $rewrite_args["walk_dirs"] = false;
    $wp_rewrite->add_permastruct( $post_type, $permalink, $rewrite_args);

    But somehow it doesn’t feel right.

  • The topic ‘Special Permalink structure, anybody?’ is closed to new replies.