WordPress.org

Support

Support » Themes and Templates » [Resolved] template_redirect issues with the Slug

[Resolved] template_redirect issues with the Slug

  • Hey ppl,
    I am building a WordPress theme that incorporates the “template_redirect” action hook…

    Basically I have a special page items I want to show on the WordPress Site like so (considering the main site is where the WordPress is installed):

    http://mydomain/item/1/hello-world/

    The “template_redirect” identifies any page that starts with item and follows a digit through a Regex like so:

    if(preg_match('/item\/(\d+)\//',$_SERVER["REQUEST_URI"]){
    //DO STUFF HERE TO SHOW MY OWN ITEM CODE
    }

    This works fine until I add a post that has “item” in its slug – for example I added a post “Item is running low” – which created the slug “item-is-running-low”

    Now when I try to get:
    http://mydomain/item/1/hello-world/

    The system thinks its the post and re-directs the page to the post as oppose to my special page…

    Any thoughts??? why is this happening?

    I’m using my permalinks setting at “Month and name” settings

    At the moment the only fix was to re-arrange the slug into “running-low-on-item”
    which sorted the problem as “item” was not in the first word in the slug.

    Please help…

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] template_redirect issues with the Slug’ is closed to new replies.
Skip to toolbar