Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The default author permalink is:

http://domain.com/author/{username}

How can I do something like this ?

http://domain.com/author/{username}/songs 
http://domain.com/author/{username}/books
http://domain.com/author/{username}/movies

If someone visit songs permalink, wp should display songs of the respective author. If someone visit books permalink, wp should display books of the respective author, and so on! Any idea about how can I do this !?

Later edit mySQL table: favs

  • id
  • post_id
  • author_id
  • fav_type (song, book, movie)
share|improve this question

1 Answer 1

Assuming you are using custom post types for songs, books etc:

function add_rewrite_rules($rules) {
    $newrules['author/([^/]+)/songs/?$'] = 'index.php?post_type=songs&author=$matches[1]';
    $newrules['author/([^/]+)/songs/page/?([0-9]{1,})/?$'] = 'index.php?post_type=songs&locations=$matches[1]&paged=$matches[2]';

    $rules = $newrules + $rules;
    return $rules;
}

function flushRules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');

/* This function should only really be run once per change of rules - comment out */
add_filter('init','flushRules');

Try the query strings above "index.php?post_type=songs&author=username" and make sure you get the correct post listing you are after on your site (you might need to disable permalinks to test them).

Then you can add the rules in to the function (taking note of the paged rule for each post type).

I am doing exactly this on a live site now, so it is possible - just requires a bit of patience to get the rules correct.

If you are not using custom post types you can change the query strings above from post_type=xxx to taxonomy=tagname or whatever you need to get the listing you want.

share|improve this answer
    
Thanks @Chris! The problem is i don't have taxonomies or post_types... Those songs, movies, books are inserted into a separate mysql table (because is an "add to favorites" system and I want to display favorite songs, movies, books for each author) –  Robert Dec 13 '10 at 16:34
    
@Robert - update your question to explain the structure of these tables - how on earth were we meant to know that originally!? –  TheDeadMedic Dec 13 '10 at 17:52
    
@TheDeadMedic: question updated! –  Robert Dec 13 '10 at 18:01
    
Answer found here: wordpress.stackexchange.com/questions/4243/… –  Robert Dec 13 '10 at 20:58

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.