admin管理员组文章数量:1287956
I have recently upgraded from wordpress 4.7 to 5.8 (I know a bit of a big jump).
In the old version I could dynamically change the page content using the following url structure: example.local/courses/1234/?title=something In this example, the url will remain the same, but contents of course id#1234 is loaded into the page. Since the upgrade what happens now is that the website goes to the homepage of the website ie. example.local so it seems that it is not interpreting the url parameters at all.
If I don't add anything to the end of the url ie. example.local/courses/, then the page shows the list of courses (so this is still working fine).
My functions.php file has not changed (as I didn't upgrade the theme) and my .htaccess hasn't changed.
Ive flushed the permalinks each time I make a change but still no help.
The url that does work however is example.local/courses/?id=1234&title=something so I could resort to this. However it isn't ideal as google has indexed the website (and the other websites as it is a multisite) using the old url structure.
Thanks in advance for any help at all.
Update with some extra info:
- the title parameter does nothing - it is just there for SEO purposes.
- I have disabled all plugins (minus the one I wrote that handles the display) and it still doesn’t work
- my custom plugin and parent (I didn’t upgrade this) and child theme are exactly as they were under the old wp version
- my customised template handles getting the URL parameters however this file doesn’t even seem to run now when you use the URL with /courses/1234/ as I have an exit at the start and that doesn’t run.
- in my custom template I extract the courses id ie 1234 which I use to call some Ajax which gets the course details from an external source and displays the results
- the only rewrite rule I have handles 404 errors to stop wp guessing the correct page
I have recently upgraded from wordpress 4.7 to 5.8 (I know a bit of a big jump).
In the old version I could dynamically change the page content using the following url structure: example.local/courses/1234/?title=something In this example, the url will remain the same, but contents of course id#1234 is loaded into the page. Since the upgrade what happens now is that the website goes to the homepage of the website ie. example.local so it seems that it is not interpreting the url parameters at all.
If I don't add anything to the end of the url ie. example.local/courses/, then the page shows the list of courses (so this is still working fine).
My functions.php file has not changed (as I didn't upgrade the theme) and my .htaccess hasn't changed.
Ive flushed the permalinks each time I make a change but still no help.
The url that does work however is example.local/courses/?id=1234&title=something so I could resort to this. However it isn't ideal as google has indexed the website (and the other websites as it is a multisite) using the old url structure.
Thanks in advance for any help at all.
Update with some extra info:
- the title parameter does nothing - it is just there for SEO purposes.
- I have disabled all plugins (minus the one I wrote that handles the display) and it still doesn’t work
- my custom plugin and parent (I didn’t upgrade this) and child theme are exactly as they were under the old wp version
- my customised template handles getting the URL parameters however this file doesn’t even seem to run now when you use the URL with /courses/1234/ as I have an exit at the start and that doesn’t run.
- in my custom template I extract the courses id ie 1234 which I use to call some Ajax which gets the course details from an external source and displays the results
- the only rewrite rule I have handles 404 errors to stop wp guessing the correct page
1 Answer
Reset to default 0After a lot of research and trying different things, I came across this page https://core.trac.wordpress/ticket/50976 which wasn't exactly the same as my problem, but the cause of this was also what broke my site.
To get around this, without having to change my URL structure and therefore get google to reindex all my pages, I had to get a list of all the pages using certain templates (that made use of the example.local/courses/1234/?title=something) and then create an add_rewrite_rule for each of the pages.
/**
* Register new rewrite rules
*/
function rewrite_pagination_rules_for_content_items() {
/* get list of pages the rewrite is required for based on a particular template used */
$pages = get_list_of_paginated_pages();
foreach($pages as $page) {
/* strip off domain name and first slash */
$domain_start = strpos($page['url'],'://');
$domain_finish = strpos($page['url'],'/',$domain_start+3);
$url = substr($page['url'],$domain_finish+1);
$post_id = $page['id'];
//echo '<br/>url = '.$url.' post id = '.$post_id;
add_rewrite_rule("^(.*){$url}([0-9]*)/?$",
'index.php?page_id='.$post_id,
'top');
add_rewrite_tag('%id%','([0-9]*)');
}
}
add_action('init', 'rewrite_pagination_rules_for_content_items');
本文标签: url rewritingURL structure for dynamic content broken since upgrade to 58
版权声明:本文标题:url rewriting - URL structure for dynamic content broken since upgrade to 5.8 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741331016a2372764.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
title
a custom parameter in your template? How is/courses/1234
implemented? WP Rewrite rules? Is1234
a post ID for a course CPT? Use the edit link to update your question with all this information ( even if the answer is that you do not know ) – Tom J Nowell ♦ Commented Sep 2, 2021 at 8:54