WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] template_redirect issues with the Slug (3 posts)

  1. DaganLev
    Member
    Posted 3 years ago #

    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...

  2. DaganLev
    Member
    Posted 3 years ago #

    anybody???

  3. DaganLev
    Member
    Posted 3 years ago #

    No worries found what I needed to do;

    you can get the full explanation here if you are interested:
    http://solid-code.co.uk/2011/04/using-wordpress-to-display-custom-pages/

    With this code:
    remove_filter('template_redirect', 'redirect_canonical');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.