?
Solved

Wordpress plugin - retrieve posted value.

Posted on 2012-04-06
3
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

752 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