Solved

Wordpress plugin - retrieve posted value.

Posted on 2012-04-06
3
230 Views
Last Modified: 2012-11-21
I have something like the following code. What I am trying to do, is to retrieve the value of the variable my_favorite_variable which has been posted from the check box. I have tried with lots of different things, but am unable to do so.

Can you tell me how to do it? Would also appreciate a bit of an explanation why it is not presently working so that I can learn rather than just have the answer.

Thanks.
<?


function my_favorite_variable_checkboxes($post_type, $post) {
$my_favorite_variable=$_POST['my_favorite_variable'];
    add_meta_box(
        'wpmy_favorite_variable_box_id',          // this is HTML id of the box on edit screen
        'WP Title Box name: ',    // title of the box
        'my_favorite_variablecheckbox',   // function to be called to display the checkboxes, see the function below
        'post',        // on which edit screen the box should appear
        'normal',      // part of page where the box should appear
        'default'      // priority of the box
	,array( 'my_favorite_variable' => $my_favorite_variable)
    );
}



add_action( 'add_meta_boxes', 'my_favorite_variable_checkboxes',10,2 );



function my_favorite_variablecheckbox( $post,$metabox) {
    wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_nonce' );


    echo 'Check the following box: <input type="checkbox" name="my_favorite_variable" id="my_favorite_variable"';
	echo ' /><br/>';
echo 'Something should appear here: '.$metabox['args']['my_favorite_variable'].
 get_post_meta($post->ID,'my_favorite_variable',true);
}

?>

Open in new window

0
Comment
Question by:shafferb1
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 37841071
Have you tried using $_REQUEST['my_favorite_variable']; instead of $_POST?

Reason being is WordPress has some code that alters the normal PHP globals for POST and GET and forces them into REQUEST.  So if you can't access your POST variables, try the REQUEST array.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38620069
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question