tags:

views:

1336

answers:

4

I want to add a custom php file to a wordpress to do a simple action.

So far I have in my theme index.php file:

<a href="myfile.php?size=md">link</a>

and the php is

<?php echo "hello world"; ?>

<?php echo $_GET["size"]; ?>

<?php echo "hello world"; ?>

The link, once clicked, displays:

hello world

Is wordpress taking over the $_GET function and I need to do some tricks to use it? What am I doing wrong?

Edit:

<?echo "hello world";?>
<? 
  if (array_key_exists('size', $_GET))
    echo $_GET['size'];
?>
<?echo "end";?>

Ouputs :

hello world
A: 

Try this:

<?echo "hello world";?>
<? 
  if (array_key_exists('size', $_GET))
    echo $_GET['size'];
?>
<?echo "end";?>

If you see

hello worldend

... that means you're not setting the size GET parameter. What URL are you using to access said page?

cdmckay
I get "hello world" :\
marcgg
Try putting <?php error_reporting(E_ALL); ?> at the top and see if you get any meaningful errors.
cdmckay
it's not displaying anything
marcgg
+1  A: 

Not sure if this will show anything but try turning on error reporting with:

<?php
   error_reporting(E_ALL);
   ini_set('display_errors', true);
?>

at the top of your page before any other code.

Edit:

From the OP comments:

silly question, but are you sure you are viewing the results of your latest changes to the file and not a cached copy of the page or something? Change "hello world" to something else. (Sorry grasping at straws, but this happened to me before) – Zenshai

ahaha, the person that were doing the changes didn't changed the correct file. It's working now – marcgg

peer programming fail ^^ – marcgg

That would be an "or something", can't tell you how many times i've done something like that. Glad you were able to figure it out in the end. – Zenshai

I usually discover errors like these only when they begin to defy everything I know about a language or an environment.

Zenshai
it's not displaying anything
marcgg
update your answer and I'll accept it
marcgg
thanks for your help. What a silly problem :)
marcgg
A: 

Wordpress does not take $_GET over. Are you sure that you are passing the variable correctly?

If you hardcode the variable in a url, make sure it is of this form:

YOUR_SITE_PATH/?variable_name=variable_value

please not the "/" at the end of the url, before the "?"

I cannot see your index.php code, but make sure that the variable "size" is either set manually in the url or from a submitted form. If you use a form, make sure that you use the method="GET". If you use method="POST", then your variable will be in $_POST['size'].

Hope this helps.

Regis Zaleman
I think so, the path is : http://website.com/blog/fontSwitcher.php?size=md. I updated the index.php code
marcgg
website.com/blog/fontSwitcher.php/?size=md doesn't work either
marcgg
A: 

You may want to take a look at WP's documentation about the WP Query object.

http://codex.wordpress.org/Query_Overview

It seems like wordpress uses the get_query_vars to method of the wp_query object to get queries.

You may also take a look at this one: http://codex.wordpress.org/Custom_Queries

Guillaume Flandre