Custom Post Types, Custom Taxonomies and Permalinks ?

So let’s say i register a custom taxonomy called:

Clients

With a few terms such as: Microsoft, IBM, Apple

Read More

Under a CPT (custom post type) called projects:

Permalinks

/%year%/%monthnum%/%taxonomy%/%postname%/ this is the structure i am using;

http://www.example.com/projects/ – Displays All posts under ‘projects’

http://www.example.com/projects/clients/ Displays a 404

http://www.example.com/projects/clients/ibm/ displays all posts under projects with the term ibm

How can i get WordPress to display an Index of all the posts under Clients? so for example if the user visited /projects/clients/ all the posts with Microsoft, Apple and IBM would be displayed.

I know a method is to use a page and then query into the page, but in essence of SEO, and relevance, i can not name the page-slug something else.

Thanks in advance.

Related posts

Leave a Reply

2 comments

  1. You need to write a custom rule. I did similar stuff for a recent project. Create a template, and assign it to a page, with slug as ‘clients’ (or anything you like, but change the slug in the following rule as well). Try the following code, use functions.php:

    add_action('init', 'custom_rule');
    function custom_rule()
    {
        global $wp, $wp_rewrite;
        $wp_rewrite->add_rule('^projects/clients/', 'index.php?pagename=clients', 'top');
    }
    

    Then on that template, form a custom query with your desired params (clients taxonomy) and loop through it.

    Note: After you put the above code in your functions.php file, go to
    Settings > Permalinks, and click on save.

    Hope this helps (I recommend you try it locally first)!

  2. You cannot access the clients location because its not a term, its your taxonomy base.

    http://www.example.com/projects/clients/ is taxonomy base. Its like accessing http://www.example.com/tags/ which doesn’t work.

    http://www.example.com/projects/clients/ibm/ is taxonomy term URL. Its like accessing http://www.example.com/tags/example which works.

    If you want to access /clients/ URL then you should create a page with custom template that can display the contents of all posts under /clients/ taxonomy.