• Skip to main content

Julian Thomas Screawn

B.A. ,B.ED. ,M.ED.

  • Home
  • About
  • Websites
  • Resources
  • Coding
  • Contact

Add field data from a Custom Post Type to a Formidable field

2025/05/16

add_filter('frm_setup_new_fields_vars', 'add_a_field_function', 20, 2);
add_filter('frm_setup_edit_fields_vars', 'add_a_field_function', 20, 2);

function add_a_field_function($values, $field){

	if($field->id == 15){
		$arrayPositions = array();
		$pushobj = array(
			'value' => "",
			'label' => "Select an Event..."
		);
		array_push($arrayPositions, $pushobj);
		$positionQuery = new WP_Query( array( 'post_type' => 'event', 'posts_per_page' => -1, 'orderby' => "menu_order", 'order' => "ASC") );
		if ( $positionQuery->have_posts() ) {
			while ( $positionQuery->have_posts() ) {
				$positionQuery->the_post();
				
				$title=get_the_title();
				$price=get_field('price');
				$label=$title." (".$price.")";
				
				$pushobj = array(
					'value' => get_the_title(),
					'label' => $label
				);
				array_push($arrayPositions, $pushobj);
			}
			wp_reset_postdata();
		}

	   	$values['options'] = $arrayPositions;
	}
	return $values;
}

Filed Under: Wordpress

Copyright © 2025 · Servicing Moncton, Dieppe, Riverview and beyond! · Moncton Meditation · Moncton English Tutor