Your question implies that index.php
is a page to be redirected to, it isn’t, it’s purely a template file. It implies that single.php
being loaded is what makes a page singular, or that loading the page.php
template will give you a page, when it’s actually the other way around.
I strongly recommend reading about the template hierarchy, it should answer your question, and make a few things about WordPress chooses a template file to load in your theme make a lot more sense.
Specifically WordPress:
- Uses rewrite rules to match the URL to a set of query variables to pass into a database query
- Passes those through the
pre_get_posts
filter then makes the query to grab posts - Uses those query variables to choose a template
E.g. if the s
query var is present, then is_search()
will return true, and WordPress will look for a search.php
theme template to load. If it doesn’t exist, it loads the fallback, archive.php
, and if that doesn’t exist it loads the final fallback index.php
.
In your custom taxonomy case it will load these files in this order until it finds one:
taxonomy-$taxonomy-$term.php
taxonomy-$taxonomy.php
taxonomy.php
archive.php
- if paged=true:
paged.php
index.php
Were $taxonomy is the internal name of your taxonomy ( as used in register_taxonomy
), and $term
is the ID of the taxonomy term.