I'm trying to pass two values to another page. Both pages are WordPress page templates.

First, I pass the value as such:

<tr onclick="window.location.href='http://www.areal-agro.nl/tool/?page_id=780&amp;user=<?php 
            urlencode( the_title() );
            echo urlencode($current_aanvraag) ;

Then, in the other file, I accept these two variables

$doorgekregenuser = $_GET['user'];
    if ($doorgekregenuser != ''){
        $doorgekregenuser = urldecode($doorgekregenuser);
        update_usermeta( $current_user->id, 'current_user', $doorgekregenuser );
    if ($doorgekregenaanvraag != ''){
        $doorgekregenaanvraag = urldecode($doorgekregenaanvraag);
        update_usermeta( $current_user->id, 'current_aanvraag', $doorgekregenaanvraag );

If I only try to pass the user variable it works. When I add the second one it won't work anymore. If I echo the second value on the page, it says:

aanvraag van Geling H. te Oploo op 6 februari 2013 om 11:16 op 14 maart 2013 om 11:17

When I encode it, it passes this in the url:


Every time I try this, it sends me to a 'Page not found'-page. Any suggestions on how I might be on the wrong track?

  • If I pass the right value directly in the variable, it does work. $doorgekregenaanvraag = 'aanvraag van Geling H. te Oploo op 6 februari 2013 om 11:16 op 14 maart 2013 om 11:17'; – Lars van Peij Mar 27 '13 at 10:51

I'm assuming these are the post details the you're trying to pass through the URL. Not sure if that is the most effective way to go about doing this. I do the same type of thing, but pass the postID through the URL and when I get to the destination page, use the postID to collect the necessary information. If you're working with multisite, make sure to also pass the blogID and then you can get the title, publish date and all the other information that is adding the crazy characters.

All-in-all it's not great practice to pass all that info via url, so I'd suggest only passing what you absolutely need.

Also, make sure you have declared your custom variable in functions.php so you can use in your URL. That is done like so:

function add_variables() {
  global $wp; 
  • I am now passing only the post_ID, but that also fails: www.areal-agro.nl/tool/?page_id=780&user=724&aanvraag=725 – Lars van Peij Mar 27 '13 at 13:35
  • What would it look like to declare custom variable 'aanvraag' and 'user'? – Lars van Peij Mar 27 '13 at 13:37
  • It seems to be the problem that my variables are named incorrectly? The user variable works, but the aanvraag variable doesn't.. Still don't get it – Lars van Peij Mar 27 '13 at 13:50
  • I've found another way, using areal-agro.nl/tool/?page_id=780&amp;user=<?php echo get_the_ID() . '.' . $current_aanvraag_id ;?> and $doorgekregenuser = $_GET['user']; if ($doorgekregenuser != ''){ $doorgekregeninfo = explode('.', $doorgekregenuser); update_usermeta( $current_user->id, 'current_user', get_the_title($doorgekregeninfo[0]) ); update_usermeta( $current_user->id, 'current_aanvraag', get_the_title($doorgekregeninfo[1]) ); } – Lars van Peij Mar 27 '13 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.