Wordpress plugin - retrieve posted value.

8 replies
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);
}

?>
#plugin #retrieve #wordpress

Trending Topics