php - url not using query string no longer working

admin2025-01-07  3

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;
Share Improve this question edited Jul 2, 2021 at 17:26 trundles asked Jun 30, 2021 at 17:51 trundlestrundles 234 bronze badges 4
  • It would really help if you just included the code. It's impossible to say anything without it. – Jacob Peattie Commented Jul 1, 2021 at 16:07
  • what code should I post? Something is redirecting/rewriting the url from /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:12
  • “ I have coded a custom feature to get data from the database” – Jacob Peattie Commented Jul 2, 2021 at 2:10
  • So I've added some code to the post... I have a website that has identical code on 2 different pages. One works, and the other does not. so the one that works keeps the url (ie: example.com/item/123/) and the one that does not converts the url from example.com/test/123/ and changes it to example.com/test/ – trundles Commented Jul 2, 2021 at 17:25
Add a comment  | 

1 Answer 1

Reset to default 0

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736256952a401.html

最新回复(0)