Title: Call php code with Query String
Last modified: August 20, 2016

---

# Call php code with Query String

 *  Resolved [trubdor](https://wordpress.org/support/users/trubdor/)
 * (@trubdor)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/call-php-code-with-query-string/)
 * Greetings,
 * I have a wordpress page that contains custom php code.
    Let’s say the page name
   is called myphpcode. I have a url that looks like: [http://www.mysite.com/myphpcode/var1-var2-var3](http://www.mysite.com/myphpcode/var1-var2-var3)
   The var1-var2-var3 is meant to be a hyphen delimited parameter list that the 
   myphpcode program will parse as a query string.
 * The wordpress site is using a permalinks setting: /%postname%/
    Thus the other
   links for posts look like: [http://www.mysite.com/category/my-first-topic](http://www.mysite.com/category/my-first-topic)
   [http://www.mysite.com/category/my-second-topic](http://www.mysite.com/category/my-second-topic)
   [http://www.mysite.com/top-ten-holiday-gift-ideas](http://www.mysite.com/top-ten-holiday-gift-ideas)
 * So, in this example, I am assuming
    my-first-topic and top-ten-holiday-gift-ideas
   function like an html file.
 * When I call [http://www.mysite.com/myphpcode](http://www.mysite.com/myphpcode)
   
   the code runs OK and a default page is displayed since it has not yet received
   any query string values.
 * When I call [http://www.mysite.com/myphpcode/var1-var2-var3](http://www.mysite.com/myphpcode/var1-var2-var3)
   
   wordpress says The page you requested could not be found.
 * I am using the following .htaccess
 * RewriteEngine On
    RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{
   REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^myphpcode/(.*)
   $ [http://www.mysite.com/myphpcode?parm1=$1](http://www.mysite.com/myphpcode?parm1=$1)[
   QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-
   d RewriteRule . /index.php [L]
 * I was hoping the RewriteRule with the myphpcode reference
    would execute the 
   myphpcode and pass the var1-var2-var3 as a query string into parm1. I am guessing
   that it sees the myphpcode as a wordpress category instead of a wordpress page
   with php code and that it sees the var1-var2-var3 as html code which of course
   it is not.
 * Since I am relatively new to wordpress I am in need of some
    more experienced
   eyes.
 * Thank You.

Viewing 1 replies (of 1 total)

 *  Thread Starter [trubdor](https://wordpress.org/support/users/trubdor/)
 * (@trubdor)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/call-php-code-with-query-string/#post-2576984)
 * I found the solution to using a URL such as
    [http://www.mysite.com/myphpcode/var1-var2-var3](http://www.mysite.com/myphpcode/var1-var2-var3)
   in a wordpress page containing custom php code and custom permalinks such as /%
   postname%/
 * The solution is described here:
    [http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/](http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/)
 * If you read this you will see that you need to update two php mpodules.
    You 
   must change functions.php located in the root folder for the specific wordpress
   theme you are using. The other module to change would be your own custom php 
   code where you want to interpret the URL that has just been pressed. Note: In
   my situation, myphpcode is a program that keeps getting called with different
   values in the query string. My program, myphpcode, knows how to interpret these
   query string values because it created the href links in the first place.
 * Thus, in my example, [http://www.mysite.com/myphpcode/var1-var2-var3](http://www.mysite.com/myphpcode/var1-var2-var3)
 * myphpcode is a wordpress Page that contains my custom php code and
    var1-var2-
   var3 is acting as a query string.
 * The problem was that wordpress did not recognize this URL.
    By default I believe
   it tried to interpret myphpcode like category in a standard wordpress URL with
   a Post called my-first-topic. For example, [http://www.mysite.com/category/my-first-topic](http://www.mysite.com/category/my-first-topic)
   is a standard structure for many wordpress posts.
 * I wanted wordpress to recognize myphpcode as a wordpress page containing php 
   code. This can be accomplished using the add_rewrite_rules function described
   at [http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/](http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/)
 * Here is the complete code as it relates to the URL I have been describing: [http://www.mysite.com/myphpcode/var1-var2-var3](http://www.mysite.com/myphpcode/var1-var2-var3)
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * In any event, the code added to functions.php did help define my URL with my 
   program and query string to wordpress. I was then able to get the pagename and
   query string from $_SERVER[“REQUEST_URI”]
 * The wordpress site that is actually using this code can be viewed at
 * [http://babynamesdiary.com/baby-names-and-meanings/baby-names-A-1/](http://babynamesdiary.com/baby-names-and-meanings/baby-names-A-1/)
 * In this URL, baby-names-and-meanings is a wordpress page containing my custom
   php code and baby-names-A-1 is the query string.
    The customer for whom I created
   this application wanted the URL this way for SEO purposes. Hope this helps. Buona
   Fortuna!

Viewing 1 replies (of 1 total)

The topic ‘Call php code with Query String’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [Query String](https://wordpress.org/support/topic-tag/query-string/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [trubdor](https://wordpress.org/support/users/trubdor/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/call-php-code-with-query-string/#post-2576984)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
