0

The hierarchy picture doesn't tell me exactly which one is dominant.

/search/query/?category_name=general&post_type=custom
/category/general/?s=query
/tag/any/?s=query
/custom_post/?s=query&custom_tax=term
/?s=query&custom_tax=term&post_type=custom

When I tested the links I gave above, I could not draw any conclusions. When we open these links, I do not understand which archive file it prefers.

Sometimes it goes to archive.php while opening search.php in some cases.

Outside of this hierarchy, is there any indication of what it prefers when it comes to equivalence?

1
  • /search/query is not a WordPress rewrite rule, it's a custom rewrite rule added by a plugin or theme. Can you not use a debugging tool to test which template it loads? Or inspect the body class? Note that WordPress is not a man woman or person, use it instead of he/she/they – Tom J Nowell Mar 3 at 13:40
0

The answer is simple:

  • /search/query/?category_name=general&post_type=custom is not a part of WordPress and has been added by a plugin/theme, you need to ask their support or inspect the code to find out

For everything else, if is_search() is true, then it's a search archive. If is_search() is not true it is not a search archive.

Since all of those URLs have ?s= they are all searching for things, so they are all search archives.

We know this because it shows search.php, and because the body class is:

class="archive search search-results category category-maintenance category-39 logged-in admin-bar  customize-support"

You shouldn't need to know the priority of template to know which template is currently loaded. WordPress shares this information openly if you built the theme correctly, debugging tools will tell you, and you can always put this is the search template at the top of search.php and see if the text appears.

2
  • actually I did as you said. The path /?s=query&post_type=custom matches search.php. But if I add archive- {custom} .php in the directory, it matches archive- {custom} .php instead of search.php. Actually, that was the reason for all my confusion. If a search has been done is there no way to force it to match search.php? – Pelmi Mar 3 at 13:59
  • It may then believe that it is a post type archive, the body class will indicate if this is the case. I'd also recommend installing the query monitor plugin which provides more information – Tom J Nowell Mar 3 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.