try it with:
<?php
echo "<input type='checkbox' name='pp_is_feat_meta' id='pp_is_feat_meta' value='1' ".checked(1, get_option('pp_is_feat_meta'), false)." />";
?>
http://codex.wordpress.org/Function_Reference/checked
Hey, thanks, and nope, still the same… I guess that false at the end just makes sure that the checked=”checked” does not get displayed in browser.
I am actually concerned if get_option(‘pp_is_feat_meta’) part is correct
For testing purposes try echoing the pp_is_feat_meta option and see what it returns:
echo 'pp_is_feat_meta = ' . get_option('pp_is_feat_meta');
How do you save the forms options?
Hey keesiemeijer, thanks again.
I tried echoing that, but all it displays is:
pp_is_feat_meta =
Which means, there is nothing in get_option(‘pp_is_feat_meta’); which is why the problem is i suppose.
I also tried manually adding checked=”checked” within the input, like so:
echo "<input type='checkbox' name='pp_is_feat_meta' id='pp_is_feat_meta' value='1'
checked='checked' />";
And here, the check-box remains checked, which means the only issue is to find out how to get the check-box state (in our case we are using get_option(‘pp_is_feat_meta’);, which doesn’t seem to work)
As for saving the form options:
add_action('save_post',function($post_id){
global $post;
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
if($_POST && wp_verify_nonce($_POST['pp_nonce'], __FILE__)) {
if(isset($_POST['pp_is_feat_meta'])){
update_post_meta($post->ID, 'pp_is_feat_meta', $_POST['pp_is_feat_meta']);
}
}
this one here, saves it on update.
Try it with this:
add_action('save_post','save_pp_is_feat_meta');
function save_pp_is_feat_meta($post_id){
global $post;
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
if($_POST && wp_verify_nonce($_POST['pp_nonce'], __FILE__)) {
if(isset($_POST['pp_is_feat_meta'])){
update_post_meta($post_id, 'pp_is_feat_meta', $_POST['pp_is_feat_meta']);
}
}
}
Can you paste and submit the full code of your metabox code into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.
http://pastebin.com/jhwFFCDu
Here you go Sir.
keesiemeijer, You sir, are a legend!!! Thank you so very much, it works like a charm now.
I would like to know what the problem was, theoretically, for example, was there an issue in my save post function??
😀
You’re welcome. Glad you got it resolved.
In your original code this line checks if the “option” in the database has the correct value.
<?php checked('1', get_option('pp_is_feat_meta')); ?>
While it is saved in the database as a “custom field”:
update_post_meta($post_id, 'pp_is_feat_meta', $_POST['pp_is_feat_meta']);
And for both input form fields the name was “name=”pp_is_feat_meta”. For some type of input fields this will only put the last name value in the $_POST array. Thats why I made it an associative array: name="pp_is_feat_meta[featured]"
I hope this all makes sense.
well , makes a bit of sense only as of now, but since i am a beginner, can’t expect much from myself… Thanks again.
We were all beginners once. keep at it!