Custom Fields
Re-Envisioned
Support General Group or not?

  • Creator
    Topic
  • #31111
    Resolved info@ceescoenen.nl
    Participant

    I make a portfolio website with all my projects. With Custom Fields I fill all my project fields. I will make a group with tasks in a project

    #1 : website development : a lot of text
    #2 : photography : a lot of text
    #3 : SEO : a lot of text

    Do I make a group in the custom fields, make this group-field clonebale and the add three different subfields to the group?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #31112
    Long Nguyen
    Moderator

    Hi Cees,

    Do you need to add more #1, #2, #3 items? If yes, you can create 3 cloneable fields textarea or wysiwyg.

    If not, just create 3 fields textarea or wysiwyg. It is based on your requirements.

    #31113
    info@ceescoenen.nl
    Participant

    Hi,

    Yes I need sometimes one, sometimes three etc. But each clonable row has three or four fields:
    - taskname
    - task-number
    - tasktext

    I is true that I have to use a group for this?

    #31118
    Long Nguyen
    Moderator

    Hi,

    I think creating a cloneable group is a good way. You can add more tasks with a set of tasks for each row.

    #31121
    info@ceescoenen.nl
    Participant

    It won't display at the front-end. What is wrong? I have a group_id pj_taken and two subfields pj_taak and pj_taak_text. I also don't understand the ??'' in the code sample from your website.

    $group = rwmb_meta( 'pj_taken' );
    if ( empty( $group ) ) {
    }
    
    $output = '';
    
    // Sub-field title.
    $title = $group['pj_taak'] ?? '';
    $output .= '<h3 class="my-title">' . $title . '</h3>';
    
    
    // Sub-field description.
    $desc = $group['pj_taak_text'] ?? '';
    $output .= '<div class="my-description">' . wpautop( $desc ). '</div>';
    echo $output;
    

    ?>

    #31123
    Long Nguyen
    Moderator

    Hi,

    If it's the cloneable group, you need to use a loop to iterate through group elements. For example:

    $group_values = rwmb_meta( 'pj_taken' );
    if ( ! empty( $group_values ) ) {
        foreach ( $group_values as $group_value ) {
            $value = isset( $group_value['pj_taak'] ) ? $group_value['pj_taak'] : '';
            echo $value; // Display sub-field value
        }
    }

    Get more details on the documentation https://docs.metabox.io/extensions/meta-box-group/#getting-sub-field-values

    #31124
    info@ceescoenen.nl
    Participant

    Hi Long,

    Sorry.. it gives a Eval()'d code error and I can't figure out why.

    #31125
    info@ceescoenen.nl
    Participant

    Found!! Missing one } 🙂

    Sorry.

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