$_POST Superglobal not working
-
Howdy…
Love this plugin!
I am new to WP and am wondering if my problem lies beyond my code.
I have the following code in a snippet:
—————————-
function elective_metabox() {
$screen = get_current_screen($page);
if( ‘add’ != $screen->action){ //echo ‘'; print_r($screen); echo '
‘;
add_meta_box(
‘elective_selector’, // Unique ID
__(‘Elective Option’), // Box title
‘elective_metabox_html’, // Content callback, must be of type callable
‘nf_sub’, // Post Type
‘side’ // Where to put it
);
}if($_POST[‘action’] == ‘editpost’) {
//echo ‘were in here’;
update_post_meta(sanitize_text_field($_POST[‘post_ID’]), ‘elective’, sanitize_text_field($_POST[‘elective’]));
}
}function elective_metabox_html($post) {
wp_nonce_field(basename(__FILE__), “meta-box-nonce”);
$course = get_post_meta($post->ID, ‘elective’, true);
?>-
Course
<br />
<select style=”width: 90%;” name=”elective”>
<option>–</option>
<option<?php if($course == “Worship Leading”) { echo ” selected”; } ?>>Worship Leading</option>
<option<?php if($course == “The Gospels”) { echo ” selected”; } ?>>The Gospels</option>
</select>
<?php
}
//die(‘mama’);
add_action(‘add_meta_boxes’, ‘elective_metabox’);
——————————When I run this snippet (enabled only in administration area) there seems to be no post data falling into the function.
I was checking by running:
echo ‘
'; print_r($_POST); echo '
‘;
inside of the elective_metabox function. The only thing that returns is an empty “array()”
Can you advise if I am using the superglobal incorrectly?
Thanks!
-
Course
The topic ‘$_POST Superglobal not working’ is closed to new replies.