Support Forum » User Profile

Forum Replies Created

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • Darren MillerDarren Miller
    Participant

    Oh man I can't thank you enough for breaking this down, I really appreciate it! This makes sense. I'm hoping I can run with this now for other applications. It's working like a charm!

    Darren MillerDarren Miller
    Participant

    @longnguyen maybe the coding is just over my head here? Do I need MB Views to accomplish this? I currently only have the Core bundle...

    Sorry to be a pest on here, I'm just working on a deadline and hoping to figure out how I'll solve this as soon as I can.

    Darren MillerDarren Miller
    Participant

    I've figured out how everything should be structured in the backend, but I'm really struggling to figure out how to display it in the frontend. I've tried to properly implement instructions in the documentation to no avail.

    Here's one thing I've tried:

    
    <?php
    $awards = rwmb_meta( 'awards_info' ); // ID of the group
    if ( ! empty( $awards ) ) {
        foreach ( $awards as $award ) {
        echo '<div class="awards">';
        echo '<p class="year">', $award['year'], '</p>'; // Access sub-field via its ID.
        echo '<p class="award">', $award['award'], '</p>';
        echo '<p class="status">', $award['award_status'], '</p>';
        echo '</div>';
    }
    }
    ?>
    

    When that didn't work, I went the shortcode route and tried this:

    
    add_shortcode( 'awards', function() {
        $group = rwmb_meta( 'awards_info' );
        if ( empty( $group ) ) {
            return '';
        }
    
        $output = '';
    
        // Sub-field year.
        $year = $group['year'] ?? '';
        $output .= '<h3 class="year">' . $year . '</h3>';
        
        // Sub-field award.
        $award = $group['award'] ?? '';
        $output .= '<h3 class="award">' . $award . '</h3>';
        
        // Sub-field award status.
        $award_status = $group['award_status'] ?? '';
        $output .= '<h3 class="award_status">' . $award_status . '</h3>';
    
        return $output;
    } );
    

    I also tried changing the code for the taxonomy advanced field ('award'):

    
    add_shortcode( 'awards', function() {
        $group = rwmb_meta( 'awards_info' );
        if ( empty( $group ) ) {
            return '';
        }
    
        $output = '';
    
        // Sub-field year.
        $year = $group['year'] ?? '';
        $output .= '<h3 class="year">' . $year . '</h3>';
        
        // Sub-field award.
        $terms = get_terms( array(
        'taxonomy' => 'award',
        'hide_empty' => false,
    ) );
        
        // Sub-field award status.
        $award_status = $group['award_status'] ?? '';
        $output .= '<h3 class="award_status">' . $award_status . '</h3>';
    
        return $output;
    } );
    

    I'm not sure what to do. In case it helps, this is the code for the metaboxes in the backend (though I'm using the Builder extension to create them):

    
    <?php
    add_filter( 'rwmb_meta_boxes', 'awards_display' );
    
    function awards_display( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'      => __( 'Awards', 'your-text-domain' ),
            'id'         => 'awards',
            'post_types' => ['page'],
            'context'    => 'side',
            'class'      => 'awards',
            'fields'     => [
                [
                    'name'              => __( 'Award Info', 'your-text-domain' ),
                    'id'                => $prefix . 'awards_info',
                    'type'              => 'group',
                    'clone'             => true,
                    'sort_clone'        => true,
                    'clone_as_multiple' => true,
                    'add_button'        => __( '+ Add Another', 'your-text-domain' ),
                    'before'            => __( '<div class="awards">', 'your-text-domain' ),
                    'after'             => __( '</div>', 'your-text-domain' ),
                    'class'             => 'awards',
                    'fields'            => [
                        [
                            'name'     => __( 'Year', 'your-text-domain' ),
                            'id'       => $prefix . 'year',
                            'type'     => 'select',
                            'options'  => [
                                2007 => __( '2007', 'your-text-domain' ),
                                2008 => __( '2008', 'your-text-domain' ),
                                2009 => __( '2009', 'your-text-domain' ),
                                2010 => __( '2010', 'your-text-domain' ),
                                2011 => __( '2011', 'your-text-domain' ),
                                2012 => __( '2012', 'your-text-domain' ),
                                2013 => __( '2013', 'your-text-domain' ),
                                2014 => __( '2014', 'your-text-domain' ),
                                2015 => __( '2015', 'your-text-domain' ),
                                2016 => __( '2016', 'your-text-domain' ),
                                2017 => __( '2017', 'your-text-domain' ),
                                2018 => __( '2018', 'your-text-domain' ),
                                2019 => __( '2019', 'your-text-domain' ),
                                2020 => __( '2020', 'your-text-domain' ),
                                2021 => __( '2021', 'your-text-domain' ),
                                2022 => __( '2022', 'your-text-domain' ),
                                2023 => __( '2023', 'your-text-domain' ),
                                2024 => __( '2024', 'your-text-domain' ),
                                2025 => __( '2025', 'your-text-domain' ),
                            ],
                            'required' => true,
                        ],
                        [
                            'name'           => __( 'Award', 'your-text-domain' ),
                            'id'             => $prefix . 'award',
                            'type'           => 'taxonomy_advanced',
                            'taxonomy'       => ['award'],
                            'field_type'     => 'select_tree',
                            'add_new'        => true,
                            'remove_default' => true,
                            'required'       => true,
                        ],
                        [
                            'name'     => __( 'Status', 'your-text-domain' ),
                            'id'       => $prefix . 'award_status',
                            'type'     => 'radio',
                            'options'  => [
                                'Nominee' => __( 'Nominee', 'your-text-domain' ),
                                'Winner'  => __( 'Winner', 'your-text-domain' ),
                            ],
                            'required' => true,
                        ],
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }
    
    Darren MillerDarren Miller
    Participant

    Thank you!

    And then if I want to use Builder to set up sub-fields in a group, would this be the right documentation to refer to?
    https://docs.metabox.io/extensions/meta-box-builder/#custom-settings

    Darren MillerDarren Miller
    Participant

    Or would groups be more on the right track? https://docs.metabox.io/extensions/meta-box-group/

    Darren MillerDarren Miller
    Participant

    Got it. Not trying to re-create the backend form fields, just the values from all of them at once. So it sounds like I can't accomplish that with the shortcode? Could I do it with the PHP code? This code looks like it would maybe result in only the term meta, but not the term itself as well?

    $term_id = get_queried_object_id();
    $value = rwmb_meta( $field_id, ['object_type' => 'term'], $term_id );
    echo $value;
    Darren MillerDarren Miller
    Participant

    Hi - yes, I've been looking at this page, and a little stumped. It looks like this is the closest thing to what I'm looking for:
    [rwmb_meta id="color" object_id="15" object_type="term"]

    I've got 3 different things to display here, as a group, all of which have their own field IDs: the custom taxonomy term itself, and 2 custom fields that have that taxonomy as their location. Essentially I'm trying to just reproduce the edit screen's fields (minus "description") on the front end.

    Can I use the shortcode to display all of that? I can't seem to figure it out. Maybe I'm just not clear on all the options I have at my disposal for "attribute" and "object type"?

    Darren MillerDarren Miller
    Participant

    Wait, I think I figured it out! I was using the Taxonomy's metabox in the page editor UI, and NOT the custom field's metabox, and so the custom field didn't register that anything was selected! I removed the taxonomy metabox from the page editor UI, and it displays properly when I check boxes in the custom field UI now.

    Now I just have to style this thing...

    Thanks for the patience here.

    Darren MillerDarren Miller
    Participant

    Also is it possible to get this to work using the shortcode within the main content area on a page? I wasn't able to get this working with the shortcode either so I'm kind of trying all avenues here, but ultimately the shortcode option would be ideal for me.

    Ultimately I'm trying to display the custom field info for a certain page within a block using the Kadence theme/blocks framework....

    Darren MillerDarren Miller
    Participant

    Thanks for the quick response!

    I changed the code to this, but now it's not rendering anything at all:

    <?php
        $terms = rwmb_meta('taxonomy_ws852srw3v');                                    
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
        foreach ( $terms as $term ) {
            echo '<p>', $term->name, '</p>';
        }
    }
    ?>
Viewing 10 posts - 1 through 10 (of 10 total)