Support Forum » User Profile

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: MB Revision only tracking the first meta field #45790
    Jonathan MinterJonathan Minter
    Participant

    Here are some screenshots. Hopefully this file sharing site works. https://postimg.cc/gallery/LS1Wzz7

    in reply to: Migrating from regular fields to a grouped field #34319
    Jonathan MinterJonathan Minter
    Participant

    I'm having some trouble with this. I've taken the snippet you gave me, plus some of the documentation on rwmb_set_values, put this inside init with priority 99 as recommended. This will be a one-time process and then I will remove it. But the rmwb_set_values function is doing nothing.

    
    add_action( 'init', function() {
    
        $sermons_a = array(
            'post_type' => 'message',
            'order' => 'DESC',
            'nopaging' => true,
        );
    
        $sermons_query = new WP_Query( $sermons_a );
    
        if ( $sermons_query->have_posts() ) {
            while ( $sermons_query->have_posts() ) {
                $sermons_query->the_post();
    
                // Get existing data
                $temp_audio = rwmb_meta( 'audio', '', get_the_ID() );
                $temp_video = rwmb_meta( 'video-id', '', get_the_ID() );
                $speakers = get_the_terms( get_the_ID(), 'speaker' );
             
                $groups = array(); // since this is a cloneable field, create an array of group values
                $group = array(); // individual group value
                $group['message_media_campus'] = 12; // literal value here
                if ($speakers) {
                    $group['message_media_speaker'] = $speakers[0]->term_id; // only using the first speaker
                }
    
                $group['message_media_audio'] = $temp_audio;
                $group['message_media_video-id'] = $temp_video;
    
                $groups[] = $group;
    
                $group_serialize = maybe_serialize( $groups );
    
                rwmb_set_meta( get_the_ID(), 'message_media_group', $group_serialize );
    
            } // end while
        } // endif
    }, 99 );
    
    in reply to: Migrating from regular fields to a grouped field #33993
    Jonathan MinterJonathan Minter
    Participant

    Okay, I see what you are saying here. I might actually create a custom function to do this and then have it loop through all my existing posts and do a one-time conversion from the old fields to the new grouped field. But I think I can step forward based on the approach you've outlined here. Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)