[resolved] How do I Pass a parameter into plugin via get request (10 posts)

  1. techxplorer
    Posted 8 years ago #

    I'm currently migrating an existing standalone web app into a WordPress plugin. What I need to be able to do is pass a parameter into the plugin that is generated as part of a get request.

    How would I go about doing this?

    Alternatively is there another way I can pass parameters into my plugin when a user clicks a link?

  2. whooami
    Posted 8 years ago #

    gets are done the same way in wordpress as in any other php based scripts...


    <?php echo $_GET["item"]; ?> is going to spit out 1

    Maybe I am missing what the difficulty is that you are experiencing?

    $my_variable = $_GET["item"];

    you just set the variable 1 in whatever the plugin is..

    you will want to define that and sanitize it though further up since you are relying on user input.

  3. techxplorer
    Posted 8 years ago #


    Yes, your right. That will work. What I am trying to work out is how do I pass a parameter to a plugin that is running inside WordPress itself.

    - I have a plugin that is rewriting some content in a page stored with WordPress accessed via the following URL


    What I want to do is have URLs like this so I can pass a parameter into the plugin


    There are two issues here.

    A. I'm not sure how the rewrite rules would affect this, because the only reason I can use this type of URL is I have permalinks configured

    B. I'm not sure how it would work if I didn't have permalinks running.

    With thanks


  4. whooami
    Posted 8 years ago #

    where is my-page/ is that outside of the admin area, ie its already being rewritten? If thats the case, I dont know how the get ought to to be handled or if you wouldnt be better of doing using an http_post instead.

  5. techxplorer
    Posted 8 years ago #


    Yes, the url to my-page/ is already being rewritten, it is a page in the WordPress system, as distinct from a post. I think I've worked out what I need to do.

    If I retrieve the URL of the request $_SERVER['REQUEST_URI'] I can determine if URLs are being rewritten. Based on my testing so far:

    - If the URL contains a ?page_id= then it is not being written and I can append my parameter onto the end and use the standard $_GET variable to get it. For example


    - If the URL does not contain ?page_id then it is being rewritten and I can append my parameter onto the end of it in a different way and still get it via the $_GET variable. For example:


    So far in my test both methods are working.

    Many thanks for your help.


  6. cinemakinoeye
    Posted 8 years ago #

    It looks like this works for one parameter, but not two parameters, e.g. mydomain.com/my_page?c=Crew works, but mydomain.com/my_page?c=Crew&s=Camera does not work, it results in a 404 error page. Is there a solution to this problem?

  7. techxplorer
    Posted 8 years ago #

    I must admit I don't know.

    In my initial investigation I only needed one parameter. What I'm going to do now is use AJAX to dynamically draw my content on the page instead. Which means I don't have to worry about parameters any more.

    Sorry I can't be of any more help.

  8. van Weerd
    Posted 8 years ago #

    I need similar functionality for a page inside wordpress. I use "pretty" url's and I can manage coding and handling e.g. http://www.mydomain.com/page?q=abcd&a=efgh links in php scripts. However, the pretty permalinks screws that up.

    techxplorer, is there a standardized way in which to do so using Ajax. I must admit I do a fait bit of php and mysql, but never came close to javascript ad ajax coding.

    might even be an option for a plugin ;-)

    any help would be greatly appreciated.


  9. techxplorer
    Posted 8 years ago #


    At the moment I must confess that I'm not sure if there is a standardised way of doing AJAX type things in the public interface of a WordPress install.

    I do know that all the components are there, for example the ability to include various JavaScript libraries that are bundled with WordPress dynamically, including loading your own external JavaScript libraries to act as the glue between it all.

    As yet though I haven't explored it too deeply. I've been working on other projects. Which interestingly enough appear to required some form of AJAX in admin pages. So in theory the same basic principles should be the same.

    My suggestion is to start by looking into either libraries made available by default via the wp_enqueue_script function.

    Sorry I can't be of much more help at the moment

  10. Top Cat
    Posted 8 years ago #

    How come the topic is marked "Resolved"?

    I'm still searching for a confirmation if
    is the right way to pass my-new-parameter to post post-name.

    It seems to work in a number of combinations like
    or even

    ..but is it fool-proof?

Topic Closed

This topic has been closed to new replies.

About this Topic