Solved

Wordpress plugin - retrieve posted value.

Posted on 2012-04-06
3
228 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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to dynamically set the form action using jQuery.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now