Dynamic Values in Contact Form 7 Fields

Dynamic Values in Contact Form 7 Fields
add_filter('wpcf7_form_tag_data_option', 'contact_dynamic_values' , 10, 3);

function contact_dynamic_values($n, $options, $args) {
  if (in_array('gigs', $options)){

  	$args = array(	'post_type'      	=> 'products',
					'posts_per_page' 	=> -1,
					'post_status'    	=> 'publish'
				);

  	$loop = new WP_Query($args);

  	$products[''] ='Select Product'; 
	if($loop->have_posts()){
		while ($loop->have_posts()) {
			$loop->the_post();

  			$products[get_the_title()] =get_the_title()  ;
  		}
  	}
    
    
    return $products;
  }
  return $n;
}

screen96

screen97

Leave a Reply

Your email address will not be published. Required fields are marked *