• twistedsymphony

    (@twistedsymphony)


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

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

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

    nor does
    https://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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter twistedsymphony

    (@twistedsymphony)

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

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

    Anraiki

    (@anraiki)

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

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

    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!

    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 https://codex.www.ads-software.com/Custom_Queries

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