Dynamic post_title

Support General Dynamic post_title

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38616
    JoJo
    Participant

    Hi,
    is there a way to populate a CTP title from different custom fields?
    I've tried to set up a text field with "post_title" ID, with this kind of value:
    {mb_bien_taxonomy_type_bien} {mb_bien_taxonomy_type_offre_bien} T{mb_bien_nb_pieces_bien} {mb_bien_commune_bien}

    but in the "all post view", the fields are not populated with the values. Hope that makes sense.
    I've tried to search in the past post here but may not be searching the right terms...

    Thanks in advance if you can point me in the right direction,
    regards,
    Jo

    #38623
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Meta Box does not support adding the field ID variable to the post title like that. If you are familiar with coding, please follow this topic to know how to update the post title from the field value https://support.metabox.io/topic/adding-metabox-field-data-to-the-post-title

    Let me know how it goes.

    #38642
    JoJo
    Participant

    Thanks a lot!
    It works, however, it doesn't if I try to add several fields. Is it possible to do that?
    I wrote it :

    function update_post_title( $post_id ) {
        // Get the field value
        $my_meta = rwmb_meta( 'nb_pieces_bien', 'type_offre_bien', $post_id );
    #38646
    Long NguyenLong Nguyen
    Moderator

    Hi Jo,

    You should get the field value separately and concatenate them later. For example:

    $my_meta1 = rwmb_meta( 'nb_pieces_bien', '', $post_id );
    $my_meta2 = rwmb_meta( 'type_offre_bien', '', $post_id );
    
    $my_post = array(
        'ID' => $post_id,
        'post_title' => $my_post_title . ' ' . $my_meta1 . ' ' . $my_meta2,
    );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.