Support » Plugin: Contact Form 7 » Output two data in one select option field

  • Resolved Michael L.

    (@michael-luther)


    Hello to all wise humans,

    I need assistance with a function that I need to customize. Hopefully someone is smarter than me. 🙂

    In a drop-down menu I need two details (workshop name and date) in one field. Both details come from the same post of a custom post type. The first detail is a post_title, the second is a custom-field from Meta-Box plugin.

    The following function works in principle, but it only returns the one or the other detail. Probably the solution is within the foreach construct. But I don’t know anything about that yet.

    How can i combine both detail to get them in one select option field?

    add_filter( 'wpcf7_form_tag', 'dynamic_field_choose_workshop', 10, 2);
    
    function dynamic_field_choose_workshop ( $tag, $unused ) {
    
        if ( $tag['name'] != 'workshop' )
            return $tag;
    
        $args = array (
            'post_type'     => 'workshop',
    	'post_status'   => 'publish',
            'orderby'       => 'name',
            'order'         => 'ASC',
            'numberposts'   => - 1,
        );
    
        $custom_posts = get_posts($args);
    
        if ( ! $custom_posts )
            return $tag;
    
        foreach ( $custom_posts as $custom_post ) {
    	$ID = $custom_post->ID;
    		$tag['values'][] = rwmb_get_value('workshop_meta_boxes_date', '', $ID);
    		$tag['raw_values'][] = rwmb_get_value('workshop_meta_boxes_date', '', $ID);
    		$tag['labels'][] = $custom_post->post_title;
        }
    
        return $tag;
    
    }

    Thank you for your support!

Viewing 1 replies (of 1 total)
  • Thread Starter Michael L.

    (@michael-luther)

    [UPDATE 2018-08-12]
    After further research, I’ve found the solution at this post. So I was right about my suspicion and changed the foreach construct accordingly.

    foreach ( $custom_posts as $custom_post ) {
        $ID = $custom_post->ID;
            $tag['values'][] = $custom_post->post_title . ' - ' . rwmb_get_value('workshop_meta_boxes_date', '', $ID);
            $tag['raw_values'][] = $custom_post->post_title . ' - ' . rwmb_get_value('workshop_meta_boxes_date', '', $ID);
            $tag['labels'][] = $custom_post->post_title . ' - ' . rwmb_get_value('workshop_meta_boxes_date', '', $ID);
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Output two data in one select option field’ is closed to new replies.