Solved

Wordpress plugin - retrieve posted value.

Posted on 2012-04-06
3
232 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article discusses four methods for overlaying images in a container on a web page
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 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…

734 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