Replace post publish date with custom field

Support General Replace post publish date with custom field

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35495
    AnLipAnLip
    Participant

    Hi !
    How can I replace the post's publish date with the value of a custom field (date-picker) ?
    I don't want to use the post's publish date because the user will use a front end form that does not support (=show) it.
    Thanks.

    #35515
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can use an MB action to update post data, for example rwmb_{$meta_box_id}_after_save_post.

    add_action( 'rwmb_versionning_after_save_post', 'update_post_title' );
    function update_post_title( $post_id ) {
        // Get the field value
        $my_meta = rwmb_meta( 'field_date_id', '', $post_id );
        
        // Preprare update post
        $my_post = array(
            'ID' => $post_id,
            'post_date' => $my_meta,
        );
        wp_update_post( $my_post );
    }

    Refer to this topic https://support.metabox.io/topic/adding-metabox-field-data-to-the-post-title/#post-34119
    and WP documentation https://developer.wordpress.org/reference/functions/wp_update_post/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.