Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 527 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$_GET and WordPress

#1
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
Reply

#2
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?
Reply

#3
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.
Reply

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

[To see links please register here]


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:

[To see links please register here]

Reply

#5
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.
Reply

#6
Although it is quite old post it might be of good use to let know.... There is one plugin that can ease handling of $_GET, $_POST and global variable declaration issues pretty well. [

[To see links please register here]

][1]


[1]:

[To see links please register here]

Reply

#7
May be this can somebody

Please check your htaccess file. and have a rewrite rule there

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase <<relative_url>>/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . <<relative_url>>/index.php [L]
</IfModule>
# END WordPress

Please change << relative_url>> with the relative url as compared to your domain

I faced the same issue and my wordpress was installed on a godaddy server . But after changing the .htaccess file the issue got resloved.
Reply

#8
See the solution :

In order to be able to add and work with your own custom query vars that you append to URLs, (eg: `www.site.com/some_page/?my_var=foo` - for example using `add_query_arg()`) you need to add them to the public query variables available to `WP_Query`. These are built up when `WP_Query` instantiates, but fortunately are passed through a filter `query_vars` before they are actually used to populate the `$query_vars` property of `WP_Query`.

For your case :

function add_query_vars_filter( $vars ){
$vars[] = "size";
return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );

and on your template page call the get methode like that :

$size_var = (get_query_var('size')) ? get_query_var('size') : false;
if($size_var){
// etc...
}


**More at the Codex** : **http://codex.wordpress.org/Function_Reference/get_query_var**

I hope it helps !
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through