WordPress.org

Ready to get started?Download WordPress

Forums

passing custom query parametrs in URL (4 posts)

  1. marc@westofpluto.com
    Member
    Posted 3 years ago #

    I have found a few bits and pieces of the answers in this forum but not all the answers. If they are indeed all there and I have missed them, then I apologize.

    In any case, here are my questions: I have a custom page that needs to make use of a custom URL parameter like this for example:

    http://www.myblog.com/mypage?kk=3

    Here "kk" is a custom parameter that my page ("mypage") makes use of. The page mypage actually executes some custom PHP code (enabled using the EXEC-PHP plugin) and this custom PHP code needs to use the kk parameter to execute properly. This page is something that goes on lots of my WordPress sites and lots of my customers' WP sites and in most cases in the past, it seems I could just use the $_GET array to get access to parameter "kk" in mypage, e.g.:

    $kk=$_GET['kk'];
    // use $kk here

    Also note that the parameter name 'kk' is just one possibility. I use several other possible parameter names like 'p' or 'pp' or 's' or ...
    But for sake of clarity in this post, I'll just refer to it as 'kk'.

    The problem is that in some WP installs, it seems that WP does not pass the kk variable in thru $_GET. Has WP changed recently so that newer versions of WP now filter out any parameter in the URL that it has not been explicitly told about before? Which versions of WP have this filtering enabled?

    My problem is that I need a very simple way for WP to turn off this filtering of unknown query parameters. I have hundreds of customers with thousands of WP sites and I need to be able to give them a simple way to make sure that any such parameter (could be kk or pa or s or several other possibilities) is NOT ignored by WP but is indeed passed in and available in the $_GET array inside the code for mypage. Is it possible to turn off this filtering?

    If it is not possible (or not a good idea), I'd like to be able to make it easy for my customers to get mypage to work properly on their sites. This URL:
    http://www.webopius.com/content/137/using-custom-url-parameters-in-wordpress
    talks about a simple plugin that a user could install. Then instead of getting the variable from $_GET, mypage would need to get the variable from the global $wp_query->query_vars array. This is OK I suppose but I really would rather make the kk variable available in $_GET so I don't have to make customers change legacy code on thousands of sites. Is there any way to do this?

    Again, I need something really easy since the solution is something I will be specifying to my customers who are nonprogrammers. A way of turning off parameter filtering on mypage is great. Or a simple plugin that makes the parameters to mypage available inside mypage would also be great.

    Thanks.

  2. marc@westofpluto.com
    Member
    Posted 3 years ago #

    No answers from anyone?

  3. AliMH
    Member
    Posted 3 years ago #

    i need this too,please help me

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    Query vars are what you need, the only difference between a registered query var is how WordPress treats it..

    Query Var not registered
    example.com/some-page/?somevar=hello
    - WordPress ignores somevar

    Query Var registered
    example.com/some-page/?somevar=hello
    - WordPress stores the value in the $wp_query->query_vars array

    ?somevar=hello this part is a query variable, the difference between registering that variable with WordPress is whether the value is stored in the WP_Query object.. (it should still be available via $_GET regardless).

    To get the value of a registered / available query variable..

    get_query_var( 'somevar' );

Topic Closed

This topic has been closed to new replies.

About this Topic