Post title and custom field

Support General Post title and custom fieldResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #31310
    marianomariano
    Participant

    Hi, I followed these directions
    https://support.metabox.io/topic/change-title-to-custom-field-using-rwmb__before_save_post-action/
    but i can't solve.

    I would like to save a custom post with the title post taken from a custom field.
    id field is text_f71tmmr7ws
    meta box ID is gruppo-campi-pazienti-orto.

    Please help me 🙂

    #31316
    Long NguyenLong Nguyen
    Moderator

    Hi Mariano,

    In your case, the code should be

    add_action( 'rwmb_gruppo-campi-pazienti-orto_after_save_post', 'update_post_title' );
    
    function update_post_title( $post_id ) {
        // Get the field value
        $my_meta = rwmb_meta( 'text_f71tmmr7ws', '', $post_id );
        
        // Preprare update post
        $my_post = array(
            'ID' => $post_id,
            'post_title' => $my_meta,
        );
    
        wp_update_post( $my_post );
    }

    Let me know how it goes.

    #35913
    Warren JohnstonWarren Johnston
    Participant

    Hi Ya Long

    Where do I find my Metabox ID to put in this code - i can find field ID's fine but cant seem to find a metabox ID

    #35917
    Long NguyenLong Nguyen
    Moderator

    Hi Warren,

    The Meta Box ID is the field group ID if you use the builder to create the custom fields. Screenshot https://monosnap.com/file/Rav02VuuBnPyZuAb3sY05sT36PpSiV

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