0

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() );
        ?>&amp;aanvraag=<?php 
            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:

http://areal-agro.nl/tool/?page_id=780&user=Geling%20H.%20te%20Oploo%20op%206%20februari%202013%20om%2011%3A16&aanvraag=aanvraag%20van%20Geling%20H.%20te%20Oploo%20op%206%20februari%202013%20om%2011%3A16%20op%2014%20maart%202013%20om%2011%3A17

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?

1
  • 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'; Commented Mar 27, 2013 at 10:51

1 Answer 1

0

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:

add_action('init','add_variables'); 
function add_variables() {
  global $wp; 
  $wp->add_query_var('my_error');
}
4
  • I am now passing only the post_ID, but that also fails: www.areal-agro.nl/tool/?page_id=780&user=724&aanvraag=725 Commented Mar 27, 2013 at 13:35
  • What would it look like to declare custom variable 'aanvraag' and 'user'? Commented Mar 27, 2013 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 Commented Mar 27, 2013 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]) ); } Commented Mar 27, 2013 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.