Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter beeblesox

    (@beeblesox)

    Nope, I think that’s the way its “supposed” to work. You could go dig through the slug creation functions and compare the custom taxonomy function to that of the normal categories.

    Good luck ??

    Thread Starter beeblesox

    (@beeblesox)

    anyone?

    Thread Starter beeblesox

    (@beeblesox)

    Ok – I figured this out.

    WordPressRoot/wp-includes/post.php, line 2793: (function wp_unique_post_slug).

    In this function, just after this line:
    } elseif ( in_array( $post_type, $hierarchical_post_types ) ) {

    there’s an sql query to make sure that the slug isn’t in use. It uses ALL hierarchical post types, instead of just the actual post type in question, which prevented using the same name even while using a separate post type.

    I changed:
    $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1";

    To:
    $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = '". esc_sql($post_type) ."' AND ID != %d AND post_parent = %d LIMIT 1";

    The change is summarized as changing:
    WHERE post_type IN ( $hierarchical_post_types )
    To:
    WHERE post_type = $post_type

    So now, when its making a unique slug, it checks only against the current post type, rather than ALL the hierarchical post types. I can now have 2 posts of the same name (as long as they’re a different post type).

    Example:
    /someposttype/cars/
    /anotherposttype/cars/

    My implementation is a bit crude, however it does work ??

    How do I motion to get this included in the next update?

Viewing 3 replies - 1 through 3 (of 3 total)