Hi,
I want to add the stick_post() and unstick_post() functionallity to a custom post type and integrated a custom checkbox field for this.
It's all working fine but the $object_id passed by the hook rwmb_after_save_post (as described in the documentation https://docs.metabox.io/actions/rwmb-after-save-post/) seems to be empty for me.
I have made this relative easy checkbox field to stick and unstick the post:
add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
$prefix = 'stick-post_';
$meta_boxes[] = [
'title' => __( 'Stick Post', 'cvh-design' ),
'id' => 'stick-posts',
'post_types' => [
'know-how'
],
'context' => 'side',
'style' => 'default',
'closed' => false,
'fields' => [
[
'type' => 'checkbox',
'id' => $prefix.'stick',
'desc' => _x('Make post sticky', 'backend', 'cvh_design'),
'columns' => 12,
],
]
];
return $meta_boxes;
});
And to check if the checkbox is ticked when the post is saved I created the following code.
The isset($_POST['stick-post_stick']) works perfectly fine I checkt the value vai a wp_mail action.
But the $object_id is empty when I try to log it into a wp_mail.
What am I missing?
add_action('rwmb_stick-posts_after_save_post', 'set_sticky_status');
function set_sticky_status($object_id) {
if(isset($_POST['stick-post_stick'])) {
stick_post($object_id);
}
else {
unstick_post($object_id);
}
}
Thanks in advance.