Support » Plugins » Custom permalink loops template code

  • Hey!

    I have a weird issue caused by adding a specific permalink structure to my theme. What I’m using is a structure where part of the URL serves as a way of feeding data into a variable. So part of the URL becomes a query var which I use in the page template that I redirect to with the rewrite rule.

    Now all is fine with this since the page is actually loading and working perfectly. The variable gets assigned and in fact I use it to display a YouTube video. The URL looks like this /watch/<youtube_video_id>/. So the YouTube video ID gets stored in a variable which is then used to load the player in the template. The problematic part is what I found out when I examined the database for video view count.

    I noticed that for every page request it logged three video views. So it seems that WordPress loads the same template file three times before it actually displays anything. I have it set so that if the user goes to /watch/ without any video ID, the variable defaults to a certain video ID. Now what gets stored in the database shows that /watch/ gets called twice (in the internal WordPress process) before /watch/<youtube video id>/ gets called. I don’t know whether this is a bug or if I’ve simply done the wrong thing when adding my rewrite rules. I’m including some code snippets so that you can help me troubleshoot. This is crucial to the performance and logging abilities of the site.

    Rewrite code

    Rewrite rules

    So I would be very grateful if somebody on the WordPress team, or someone with knowledge about how the rewrite procedure works, could help me out with troubleshooting it. I shouldn’t be the only one having this problem.

    Thanks in advance!

    Kind regards,

  • The topic ‘Custom permalink loops template code’ is closed to new replies.