0

I'm aware this may be incredibly simple, but I've just never happened to need to know this until now.

I am using custom query var and rewrite rule as follows:

$queryVars[] = 'my_query_var';
add_rewrite_rule('my-custom-page/?','index.php?my_query_var=my-custom-page','top');

I am using the Newspaper theme. No child theme.

When all is activated, permalinks flushed, and I load https://myurl.com/my-custom-page/, I am served with the standard Newspaper page.php template, which shows all posts(?) like an archive page.

I have my own tried and tested custom code that recognises when the user has navigated to the above link. It successfully processes all code, and adds to the current template at a location of my choosing. When I activate my custom query var and rewite rule, the current template changes to the above mentioned archive type of page.

How can I change this back/stop this/manipulate the template used, correctly?

Many thanks =)

3
  • Where is the code your added to your question running? The where and when parts are critical for rewrite rules. E.g. if you don't add your rewrite rule on the init hook it probably won't work. Does your non-pretty URL give you what you expected? You mentioned you have code that recognises this and works but have not shared it, and no filenames or template names are mentioned. Can you edit this information into your question?
    – Tom J Nowell
    Commented May 20 at 11:26
  • Hi I tried to keep the question is small as possible as I have a tendency to ramble. Seems I did the opposite this time. They are being run on the appropriate hooks, and I know they all work as there are others that run using the query var and some other rewrite rules. To confirm specifically: query vars are being added on the query_vars filter, and rewrite rules during init. I haven't included other code or files because they are all tried and testing as working over a period of months. It doesn't currently utilise the query vars and rewrite rules. Thanks @TomJNowell
    – user242851
    Commented May 20 at 11:42
  • If you can edit your question to clarify that, lots of people don't read the comments and things can get lost in translation, it's better to share code than to describe/paraphrase it. Currently enough of the problem has been hidden that it's difficult to fully comprehend what the problem is. Much more information and code will be needed to understand the problem, nevermind solve it. Do not post this information in the comments though, use the Edit link underneath the question tags. Avoid referring to things genericallye.g. don't say "the template", give it a name even if it's an example
    – Tom J Nowell
    Commented May 20 at 12:41

1 Answer 1

0

Normally, my-custom-page/ would be rewritten to index.php?page_id=2 (or whatever the ID of that particular page is). Your rewrite is omitting the page_id var, which is why you're getting the blog index instead of your page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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