2

When I do something like this (in my plugin function inside WP admin):

$metaboxes = get_post_meta( $post_id );
echo "<pre>";
print_r($metaboxes);
echo "</pre>";
die();

I get all my metaboxes info except the datetime.

Why is that? Where are they stored and how can I access them?

I am using this plugin http://www.deluxeblogtips.com/meta-box/ to add custom meta fields to my content type like:

array(
  'name'  => 'Date and time:',
  'type'  => 'datetime',
  'id'    => "rw_datetime",
),

I want to save the datetime field if some other field has certain value using save_post function and this is not working for datetime for some reason:

update_post_meta($post_id, 'rw_datetime', '2013-08-28 11:11' );

But something like this for a text field is working nice:

update_post_meta($post_id, 'rw_some_textfield', 'This is working!' );

Why is that? Why it's not working for datetime and why it is working for other field types?

How can I grab the datetime value if I know the $post_id and then update this field using update_post_meta() function?

UPDATE:

Code of my save_post function:

add_action( 'save_post', 'things_before_save' ); 

function things_before_save( $post_id ) { 

    // No auto saves 
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; 

    // make sure the current user can edit the post 
    if( ! current_user_can( 'edit_post' ) ) return;

    // assure the post type
    if ( ! get_post_type($post_id) == 'cards' ) return;

    // working
    update_post_meta($post_id, 'rw_some_textfield', 'This is working!' );

    // not working ;(
    update_post_meta($post_id, 'rw_datetime', '2013-08-28 11:11' );

} 

Notice that I am not working with any variables, just with strings This is working! and 2013-08-28 11:11 to eliminate possible errors.

So, I guess the problem is that rw_datetime is stored somewhere else and not at the same place as other metaboxes.

2
  • Please can you post your code? Have you checked your post meta table?
    – iEmanuele
    Aug 22, 2013 at 19:44
  • @iEmanuele I have updated my question with the code. Please, check it now, thank you.
    – Derfder
    Aug 22, 2013 at 20:00

1 Answer 1

1

it seems that you're using that plugin in a wrong way. It's not necessary hook to save_post because the plugin do it for you. Simply register your meta box and your fields. To retrieve the values check this

3
  • things_before_save = I need to make some changes in the save process depending on other things. I have just simplified stuff to not make it more complicated. Please, chcek this post for more details on my situation: wordpress.stackexchange.com/questions/111173/… It describes the reason why I need to make another function using save_post. The question is mostly solved, but I am stuck on the saving of the datetime field. Other fields can be saved without a problem.
    – Derfder
    Aug 22, 2013 at 20:43
  • @Derfder the question you linked, answered by me, do not takes into account the plugin you used. (In that question you don't say anything about any plugin) I don't know that plugin, my function is intended to work without plugins. Maybe problem is there.
    – gmazzap
    Aug 22, 2013 at 20:51
  • @G.M. Ok, I will tick your answer as solved ;). It's probably caused by that plugin.
    – Derfder
    Aug 22, 2013 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.