WordPress.org

Ready to get started?Download WordPress

Forums

Grab $_POST Variables By Key In save_post action. (4 posts)

  1. merrick.christensen
    Member
    Posted 3 years ago #

    https://gist.github.com/732629

    I have posted the plugin which uses a custom post type of 'did_you_know'. It is incredibly trimmed to demonstrate this issue. Essentially I cannot grab a value by key from $_POST['key'] but can print_r($_POST); and see it in there. I can also foreach to get the value. This is very strange behavior.

    Any help is greatly appreciated.

  2. hedronist
    Member
    Posted 3 years ago #

    My first thought was that maybe the key has an invisible character in it. What happens if you do something like var_dump(isset($_POST['did_you_know']))? You should get true.

  3. merrick.christensen
    Member
    Posted 3 years ago #

    Returns false however, var_dump($_POST) show it exists. What the heck is happening here!?

  4. hedronist
    Member
    Posted 3 years ago #

    Try doing something like this:

    print "<pre>\n";
    foreach($_POST as $k => $v) {
        print "[$k]: [$v]\n";
        print "\t" . $_POST[$k] . "\n";
    }

    Obviously the first print should show the key and value, and the second print should show the value again, but this time via indexing the array. If this loop works without blowing up then there's something about that key that is non-obvious. I would still put my money on some invisible character.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags