WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to do some WordPress URL rewriting ...

Specifically I have custom post type that currently works like this:

http://mydomain.com/videos/post-title/

But I would like to have it located at:

http://mydomain.com/videos/author-name/post-title/

Is there any way to achieve this?

share|improve this question
up vote 3 down vote accepted

using Jhon's Custom Post Permalinks plugin it should be easy using:

/%post_type%/%author%/%postname%/
share|improve this answer
    
This completely solved the issue I was having. Thanks. – Thomas May 5 '11 at 12:39
    
glad i could help. – Bainternet May 5 '11 at 14:24

You can do this with your own code, without plugins.

To accept URLs of this format, it's enough if you set the rewrite slug when you register the post type:

add_action( 'init', 'wpse16427_init' );
function wpse16427_init()
{
    register_post_type( 'wpse16427', array(
        'label' => 'WPSE 16427',
        'public' => true,
        'rewrite' => array(
            'slug' => 'video/%author%',
        ),
    ) );
}

This will also generate author archives at video/[authorname].

To generate the new URLs, you need to replace the %author% part yourself, get_post_permalink() does not do this for you. So filter the output and replace it yourself:

add_filter( 'post_type_link', 'wpse16427_post_type_link', 10, 4 );
function wpse16427_post_type_link( $post_link, $post, $leavename, $sample )
{
    if ( 'wpse16427' == $post->post_type ) {
        $authordata = get_userdata( $post->post_author );
        $author = $authordata->user_nicename;
        $post_link = str_replace( '%author%', $author, $post_link );
    }
    return $post_link;
}
share|improve this answer
    
It's important to note here that the 10,4 part of add_filter is required to make this work. The precedence can be anything, but you have to specify at least 2 in the spot where the arguments list is defined, or you will not have access to $post – Travis Weston Feb 3 at 20:35

goto the permalinks section on the settings in the admin panel, set a custom structure like so:

/%category%/%author%/%postname%/

NOTE

this assumes videos is a category

Check here for more options.

share|improve this answer
    
Videos is not a category. It's a custom post type. – Thomas May 5 '11 at 12:29
    
I think that you can just drop the /%category% bit, and Wordpress will stick the slug for your post type there anyway. – Mild Fuzz May 5 '11 at 12:33

use the following structure if you installed wordpress in a subdirectory (videos)

/%author%/%postname%/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.