WordPress.org

Ready to get started?Download WordPress

Forums

using Custom $_GET variables with Templates and Permalinks (5 posts)

  1. twistedsymphony
    Member
    Posted 6 years ago #

    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 http://mysite.com/game-db

    Ideally I'd like my get vars to incorporate something like http://mysite.com/game-db/p-val/e-val

    but even when I do
    http://mysite.com/game-db?p=p-val&e=e-val
    it does not work

    nor does
    http://mysite.com/?page_id=41&p=p-val&e=e-val

    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.

  2. twistedsymphony
    Member
    Posted 6 years ago #

    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:
    http://mysite.com/game-db?c=c-val&e=e-val

    if anyone knows how I might modify this to be
    http://mysite.com/game-db/c-val/e-val
    just within the context of the game-db page I'd love to know how.

  3. Anraiki
    Member
    Posted 6 years ago #

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

    http://mysite.com/game-db/c-val/e-val

  4. JohnnyN05
    Member
    Posted 5 years ago #

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

    Thanks!

  5. chaoskaizer
    Member
    Posted 5 years ago #

    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 http://codex.wordpress.org/Custom_Queries

Topic Closed

This topic has been closed to new replies.

About this Topic