• Resolved dwruck

    (@dwruck)


    I would like to use a field within a repeatable group to make a custom query.

    My query would be similar to this:

    'meta_query' => array(
    'relation' => 'OR',
    	array(
    		'key' => 'day_select',
    		'value' => 'off',
    		'compare' => '!='
    		),

    How would I call for the repeatable group field within this query? Here is how I call for my info normally:

    foreach ( (array) $groups as $key => $entry ) {
    	$show_time = $day_select = '';
    
    	if ( isset( $entry['show_time'] ) ) {
    		$show_time = $entry['show_time'];
    	}
    	if ( isset( $entry['day_select'] ) ) {
    		$day_select = $entry['day_select'];
    	}
    
    	$compel_output .= '<tr><th class="days">test' . $show_time .'</th><th class="time">' . $day_select .'</th><th class="trainers"></th><th class="notes"></th></tr>';
    }

    https://www.ads-software.com/plugins/cmb2/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m a little confused here.

    Are you trying to use a CMB2 field’s value in a different CMB2 field on the same admin page?

    Thread Starter dwruck

    (@dwruck)

    I am sorry for the confusion. I should have been more clear. I am using the field values for a shortcode to display the information.

    I am creating a cpt for radio station shows. The shows air at different times and days so I created a repeatable group so you can add different air times. In the shortcode I want to be be able to display all shows that occur on a particular day (i.e. Tuesday). I am hoping to use the meta_query to filter the custom field “day_select” inside the repeatable group.

    'meta_query' => array(
    'relation' => 'OR',
    	array(
    		'key' => 'day_select',
    		'value' => 'Tuesday',
    		'compare' => '!='
    		),

    Thread Starter dwruck

    (@dwruck)

    I was missing the first line from my code earlier.

    $groups = get_post_meta( get_the_ID(), 'show_repeat_group', true );
    
    foreach ( (array) $groups as $key => $entry ) {
    	$show_time = $day_select = '';
    
    	if ( isset( $entry['show_time'] ) ) {
    		$show_time = $entry['show_time'];
    	}
    	if ( isset( $entry['day_select'] ) ) {
    		$day_select = $entry['day_select'];
    	}
    
    	$compel_output .= '<tr><th class="days">test' . $show_time .'</th><th class="time">' . $day_select .'</th><th class="trainers"></th><th class="notes"></th></tr>';
    			}

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds like you’re needing the CMB2 field values for a custom WP_Query so that you can query for shows on the specific days and whatnot.

    The last post above appears to be more for the display of the actual saved values rather than initial query preparation.

    I’m following better, but it feels like we’re looking at the wrong parts of the code for the intended task at hand.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using a repeatable group field in the meta_query array’ is closed to new replies.