[resolved] posts archive page within custom taxonomy (6 posts)

  1. WakkerMedia
    Posted 3 years ago #

    Hi there,

    I hope someone can help me with this! I would certainly appreciate it!!

    I am currently working on a project where a custom taxonomy Location is the centre of the website.

    This is used to create a location-based-search within the site.
    Now, I have created several custom posts which can all be connected to the location-taxonomy. When a visitor opens the website, his location gets selected with help of GeoLocation. After that, the visitor gets redirected to: http://www.example.com/location/city

    This page shows information, news and events about the location. This is done with taxonomy-location.php.

    A custom post type company is connected to the location taxonomy. When a visitor click on the link: show companies, it needs to get redirected to: http://www.example.com/location/city/companies

    however, it gets redirected to: http://www.example.com/companies/a-random-company-name

    This is showing the content from index.php. In stead of archive-company.php.

    2 things, 1; there must be no redirection and 2; http://www.example.com/location/city/companies needs to address archive-company.php (and ofcourse, http://www.example.com/location/city/companies/a-company needs to address single-company.php).

    How can I achieve this?

    I hope someone can help me!!

    With kind regards,


  2. WakkerMedia
    Posted 3 years ago #

    okay, I have fixed one issue! The url http://www.example.com/location/city/companies doesn't get redirected anymore. I've achieved this by adding:

    'rewrite' => array( 'hierarchical' => true ),

    to my taxonomy.

    Now he only needs to show the archive-company.php file. In stead, he uses index.php.



  3. in Aachen
    Posted 3 years ago #

    Perhaps by adding something like

    RewriteRule ^location/city/companies/(.*) archive-company.php?c=$1

    to htaccess?

  4. WakkerMedia
    Posted 3 years ago #

    Hi there Aachen,

    That could work, but I thought that WordPress could handle this by its own... Like, when you would have a default blog, you can get the the content of http://www.example.com/companies/ with archive-company.php. And get a single post with http://www.example.com/companies/ company-name/ with single-company.php

    The only thing I want it to do is to use its custom taxonomy to create logical links. The taxonomy locations is used wihin all my custom posts.

    So you would get something like this:

    And again, I thought that WordPress could handle this by its own, because the way taxonomies can be used with posts.

    I hope someome could clarify this to me...

    Thnx in advance!!


  5. bcworkz
    Posted 3 years ago #

    The single-company.php file is only called as part of the WP default functioning if the requested post is a custom post type called 'company'.

    If you were to create company pages instead of posts, you could specify a company.php file or similar as a template. The taxonomy template functionality only applies to archive-like listings with a template name such as taxonomy-location.php. See Template Hierarchy for more information.

    Otherwise, you should use the Rewrite API which ends up doing a rewriterule like in Aachen suggested, but has the added benefit of registering permalink tags if need be.

  6. WakkerMedia
    Posted 3 years ago #

    Hi Bc!(And Aachen)

    Thnx for your reply. After searching for solutions in combination with the answers you both have given me, I came up with this:


    What I do is adding the ^locations/([^/]*)/companies and point it towards index.php?post_type=company

    I am not sure if this is the correct way to handle these kind of situations, but this does the trick for me!

    Thank you for helping me so far! I am marking this topic as solved.

    With kind regards,


Topic Closed

This topic has been closed to new replies.

About this Topic