Support

Account

Home Forums Add-ons Repeater Field query and return rows from repeater Reply To: query and return rows from repeater

  • Yeah, I guess I could have been more clear on that. I got it to work this way:

    function populate_cpt_titles( $form ) {
    	foreach ( $form['fields'] as $field ) {
    		if ( $field->type != 'select' || strpos( $field->cssClass, 'populate_al_products' ) === false ) {
    	    		continue;
    		}
    
    		$field->placeholder = 'Select an your product';
    
    		$args = [
    			'posts_per_page'   => -1,
    			'order'            => 'ASC',
    			'orderby'          => 'post_title',
    			'post_type'        => 'al_product', 
    			'post_status'      => 'publish',
    		];
    		$custom_posts = get_posts( $args );
    
    		$options = [];
    		foreach( $custom_posts as $custom_post ) {
    			$options[] = ['text' => $custom_post->post_title, 'value' => $custom_post->post_title];
    
                $subfields = get_field('product_variations', $custom_post->ID);
    			if ($subfields) {
                    foreach ($subfields as $subfield) {
                        $options[] = ['text' => $subfield['part_number'], 'value' => $subfield['part_number'] ];
                    }
                }
    		}
    
    		$field->choices = $options;
    	}
    	return $form;
    }