Support » Themes and Templates » using Custom $_GET variables with Templates and Permalinks

  • I’m currently working on a new site that will utilize WP as a content management system as much as a blog.

    on major feature of the site is an extensive catalog of items for which there are hundreds. I’ve created a completely custom database to store data about these items.

    In any case I created a page template that goes into my tables and fetches some data and does some things with it on the screen.

    What I need to do is get 2 $_GET vars from the url so that my script can use it in the query to return more narrow results.

    The vars are “e” and “p”

    the script works beautifully external to WP but as soon as I try to use it within WP it cannot get the vars, likely do to misinterpretation with the permalink structure.

    I have a page called “game-db” so the permalink looks like

    Ideally I’d like my get vars to incorporate something like

    but even when I do
    it does not work

    nor does

    I couldn’t find any information on working with $_get vars and permalinks… any info would be quite helpful, I’m horrible with regex and modrewrites and the way WP does them is even more foreign to me… but I am quite handy with php.

Viewing 4 replies - 1 through 4 (of 4 total)
  • after looking at it some more I discovered the problem…

    WordPress uses $_GET[‘p’] as a var for the post ID so the problem was that when I specified it it was getting confused and simply not running at all.

    changing my var to $_GET[‘c’] instead solved the problem completely. the format is now:

    if anyone knows how I might modify this to be
    just within the context of the game-db page I’d love to know how.

    You should take a look at mod_rewrite, and some part regular expression and you should clearly be on your way to getting that:

    I’ve been trying to do the same thing. I’ve tried all the ways mentioned above. I even tried using the rewrite API, using the add_rewrite_rule() function, but I couldn’t get that to work. I tried editing the .htaccess file and added my own RewriteRule (using the above as an example):

    RewriteRule ^/game-db/(.+)/(.+)/$ /game-db?c=$1&e=$2 [NC]

    That doesn’t work either. This is really easy to do outside of WordPress (obviously), but I am in need of desperate help.

    I searched the forums and there are a lot of posts, but no one has answers to this. Please help!!


    you need to register your public variables (query_vars filter hook) first then catch it with get_query_var() via ‘template_redirect’ action hook

    might want to read

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘using Custom $_GET variables with Templates and Permalinks’ is closed to new replies.