Solved

Wordpress plugin - retrieve posted value.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

23 Experts available now in Live!

Get 1:1 Help Now