I have a few websites where I have coded a custom feature to get data from the database, these are all older sites. the page fetches info by grabbing the last part of the url and turning it into the variable 'item'
example/item/12345/
this used to work, but now it no longer does. something is stripping off the last part of the url and it's just loading example/item/
The workaround of changing the url to
example/item/?item=12345
has 'fixed' it but I'd rather the other url. Can anybody shed any light on what has happened here? I believe this happened on a wordpress update a couple of versions ago.
** edit to add some code **
this is in the theme's header.php file
I use the plugin pods to create custom tables so i'm using it's db query functions
$itemURL = 'https://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$bits = explode("item/",$itemURL);
$showItem = rtrim($bits[1],"/");
$customPod = pods('custom_jewellery');
$params = array('where' => 'id = "'.$showItem.'"');
$customPod->find($params);
while($customPod->fetch()):
$customItem['id'] = $customPod->field('id');
endwhile;
I have a few websites where I have coded a custom feature to get data from the database, these are all older sites. the page fetches info by grabbing the last part of the url and turning it into the variable 'item'
example.com/item/12345/
this used to work, but now it no longer does. something is stripping off the last part of the url and it's just loading example.com/item/
The workaround of changing the url to
example.com/item/?item=12345
has 'fixed' it but I'd rather the other url. Can anybody shed any light on what has happened here? I believe this happened on a wordpress update a couple of versions ago.
** edit to add some code **
this is in the theme's header.php file
I use the plugin pods to create custom tables so i'm using it's db query functions
$itemURL = 'https://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$bits = explode("item/",$itemURL);
$showItem = rtrim($bits[1],"/");
$customPod = pods('custom_jewellery');
$params = array('where' => 'id = "'.$showItem.'"');
$customPod->find($params);
while($customPod->fetch()):
$customItem['id'] = $customPod->field('id');
endwhile;
So I never found out why this broke in the first place, but I did find a solution that forces the proper url to work
add_action( 'init', 'add_mypage_rule' );
function add_mypage_rule(){
add_rewrite_rule('^item/([^/]*)/?','index.php?pagename=item','top');
}
Sussed out from here: https://stackoverflow.com/questions/18713230/wordpress-url-rewriting-parameters-in-url
/item/123/
to just/item/
this is happening before the page loads, so before the theme files come into play – trundles Commented Jul 1, 2021 at 20:12example.com/item/123/
) and the one that does not converts the url fromexample.com/test/123/
and changes it toexample.com/test/
– trundles Commented Jul 2, 2021 at 17:25