Timeline for URL rewrite and navigation structure for wordpress custom post type
Current License: CC BY-SA 3.0
15 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 6, 2014 at 15:56 | vote | accept | nelson | ||
Nov 6, 2014 at 13:43 | comment | added | nelson | Wohooo. It now works. I did add discography rule but the mistake I was making using album_artist=$matches[1] instead of artists=$matches[1] as you have done. Thank you so much for your help. really appreciate. | |
Nov 5, 2014 at 17:43 | comment | added | Rachel Carden | You still need to include add_rewrite_rule( 'artists/([^/]+)/discography/?', 'index.php?artists=$matches[1]&discography=yes', 'top' ); If you add that back and it still doesnt work, it could be the order in which they're declared so reverse it and see if that works. I'd also download the Rewrite Rules Inspector plugin which will help you out a lot. | |
Nov 5, 2014 at 8:59 | vote | accept | nelson | ||
Nov 6, 2014 at 15:06 | |||||
Nov 5, 2014 at 8:13 | vote | accept | nelson | ||
Nov 5, 2014 at 8:54 | |||||
Nov 4, 2014 at 17:35 | comment | added | nelson | @RachelCarden I have changed my code to match the update I have posted on the functions.php snippet contained in the question. The code you supplied in the answer remains unchanged (except for me adding the artist and album slugs). album permalinks are now working perfectly. Discography however is now not working. when i put example.com/alicia-keys/discography, the page is not found. What am I doing wrong? . I solve that and everything will be complete . See the template_include filter and ex_rewrite() for the changes I made | |
Nov 4, 2014 at 16:51 | comment | added | Milo |
@nelson an added benefit to placing the rewrite tags in the rule structure is that it makes your post_type_link function simpler, you can just str_replace the tags with the correct slug instead of having to build the whole permalink.
|
|
Nov 4, 2014 at 16:49 | comment | added | Milo | @nelson as you have the slugs now, it'll generate a set of incorrect rewrite rules. you'll then have to add rewrite rules for all of your post types (don't forget pagination and feeds!), and in the end you'll end up with a set of unused rules. defining the structure when you register the post type will give you one auto-generated set of correct rules, and eliminate the need to add them. the exception is the discography rule, which isn't a post type on its own, but an intersection of two types, so that rule will need to be added manually regardless. | |
Nov 4, 2014 at 16:00 | comment | added | nelson | @Milo I would like a simple clarification: Will I have to add the slug rules you stated in your answer for the other code to work. Currently the data I have for the slugs are as follows : for artists ('slug'=>'artists'), for albums ('slug => 'albums') and for songs ('slug' => 'songs'). The plugin does provide a field where you can supply a slug rewrite rule | |
Nov 4, 2014 at 15:47 | comment | added | nelson | @Milo OK. Let me explore and then get back to you. | |
Nov 4, 2014 at 14:39 | comment | added | Milo | This is exactly why you need to register your post types and add extra rules in a precise order as I mentioned in my answer. Rules have to cascade from most to least specific. You also don't need extra rules for any singular content, those can be handled when you register post types. | |
Nov 4, 2014 at 14:06 | comment | added | Rachel Carden | If you want to add a rewrite rule for a specific album, then add add_rewrite_rule( 'artists/([^/]+)/discography/([^/]+)/?', 'index.php?artists=$matches[1]&discography=yes&albums=$matches[2]', 'top' ); BUT WordPress will only allow one post type per query so if albums are the main content, then you'll need to change 'artists' to a custom query var: add_rewrite_rule( 'artists/([^/]+)/discography/([^/]+)/?', 'index.php?album_artist=$matches[1]&discography=yes&albums=$matches[2]', 'top' ); Then setup 'album_artist' like you did 'discography' and you can use that variable in your template. | |
Nov 4, 2014 at 8:42 | comment | added | nelson | Managed to implement the code as you have displayed above, including the artist's slug. However, there's a problem and it is stemming from the discography solution I put in the code update to the question : The URL generates properly but when wordpress sees 'discography', it shows the single-artists-discography template and code execution stops there i.e. it ignores anything that follows /discography/ . What should I do to rectify | |
Nov 3, 2014 at 18:11 | comment | added | nelson | thanks for the answer.I will explore it in depth once I open business in the morning (its late night as I type this). | |
Nov 3, 2014 at 15:41 | history | answered | Rachel Carden | CC BY-SA 3.0 |