name          = 'relationship';
			$this->label         = __( 'Relationship', 'acf' );
			$this->category      = 'relational';
			$this->description   = __( 'A dual-column interface to select one or more posts, pages, or custom post type items to create a relationship with the item that you\'re currently editing. Includes options to search and filter.', 'acf' );
			$this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-relationship.png';
			$this->doc_url       = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/relationship/', 'docs', 'field-type-selection' );
			$this->defaults      = array(
				'post_type'            => array(),
				'taxonomy'             => array(),
				'min'                  => 0,
				'max'                  => 0,
				'filters'              => array( 'search', 'post_type', 'taxonomy' ),
				'elements'             => array(),
				'return_format'        => 'object',
				'bidirectional_target' => array(),
			);
			// extra
			add_action( 'wp_ajax_acf/fields/relationship/query', array( $this, 'ajax_query' ) );
			add_action( 'wp_ajax_nopriv_acf/fields/relationship/query', array( $this, 'ajax_query' ) );
		}
		/*
		*  input_admin_enqueue_scripts
		*
		*  description
		*
		*  @type    function
		*  @date    16/12/2015
		*  @since   5.3.2
		*
		*  @param   $post_id (int)
		*  @return  $post_id (int)
		*/
		function input_admin_enqueue_scripts() {
			// localize
			acf_localize_text(
				array(
					// 'Minimum values reached ( {min} values )' => __('Minimum values reached ( {min} values )', 'acf'),
					'Maximum values reached ( {max} values )' => __( 'Maximum values reached ( {max} values )', 'acf' ),
					'Loading'          => __( 'Loading', 'acf' ),
					'No matches found' => __( 'No matches found', 'acf' ),
				)
			);
		}
		/*
		*  ajax_query
		*
		*  description
		*
		*  @type    function
		*  @date    24/10/13
		*  @since   5.0.0
		*
		*  @param   $post_id (int)
		*  @return  $post_id (int)
		*/
		function ajax_query() {
			// validate
			if ( ! acf_verify_ajax() ) {
				die();
			}
			// get choices
			$response = $this->get_ajax_query( $_POST );
			// return
			acf_send_ajax_results( $response );
		}
		/*
		*  get_ajax_query
		*
		*  This function will return an array of data formatted for use in a select2 AJAX response
		*
		*  @type    function
		*  @date    15/10/2014
		*  @since   5.0.9
		*
		*  @param   $options (array)
		*  @return  (array)
		*/
		function get_ajax_query( $options = array() ) {
			// defaults
			$options = wp_parse_args(
				$options,
				array(
					'post_id'   => 0,
					's'         => '',
					'field_key' => '',
					'paged'     => 1,
					'post_type' => '',
					'taxonomy'  => '',
				)
			);
			// load field
			$field = acf_get_field( $options['field_key'] );
			if ( ! $field ) {
				return false;
			}
			// vars
			$results   = array();
			$args      = array();
			$s         = false;
			$is_search = false;
			// paged
			$args['posts_per_page'] = 20;
			$args['paged']          = intval( $options['paged'] );
			// search
			if ( $options['s'] !== '' ) {
				// strip slashes (search may be integer)
				$s = wp_unslash( strval( $options['s'] ) );
				// update vars
				$args['s'] = $s;
				$is_search = true;
			}
			// post_type
			if ( ! empty( $options['post_type'] ) ) {
				$args['post_type'] = acf_get_array( $options['post_type'] );
			} elseif ( ! empty( $field['post_type'] ) ) {
				$args['post_type'] = acf_get_array( $field['post_type'] );
			} else {
				$args['post_type'] = acf_get_post_types();
			}
			// post status
			if ( ! empty( $options['post_status'] ) ) {
				$args['post_status'] = acf_get_array( $options['post_status'] );
			} elseif ( ! empty( $field['post_status'] ) ) {
				$args['post_status'] = acf_get_array( $field['post_status'] );
			}
			// taxonomy
			if ( ! empty( $options['taxonomy'] ) ) {
				// vars
				$term = acf_decode_taxonomy_term( $options['taxonomy'] );
				// tax query
				$args['tax_query'] = array();
				// append
				$args['tax_query'][] = array(
					'taxonomy' => $term['taxonomy'],
					'field'    => 'slug',
					'terms'    => $term['term'],
				);
			} elseif ( ! empty( $field['taxonomy'] ) ) {
				// vars
				$terms = acf_decode_taxonomy_terms( $field['taxonomy'] );
				// append to $args
				$args['tax_query'] = array(
					'relation' => 'OR',
				);
				// now create the tax queries
				foreach ( $terms as $k => $v ) {
					$args['tax_query'][] = array(
						'taxonomy' => $k,
						'field'    => 'slug',
						'terms'    => $v,
					);
				}
			}
			// filters
			$args = apply_filters( 'acf/fields/relationship/query', $args, $field, $options['post_id'] );
			$args = apply_filters( 'acf/fields/relationship/query/name=' . $field['name'], $args, $field, $options['post_id'] );
			$args = apply_filters( 'acf/fields/relationship/query/key=' . $field['key'], $args, $field, $options['post_id'] );
			// get posts grouped by post type
			$groups = acf_get_grouped_posts( $args );
			// bail early if no posts
			if ( empty( $groups ) ) {
				return false;
			}
			// loop
			foreach ( array_keys( $groups ) as $group_title ) {
				// vars
				$posts = acf_extract_var( $groups, $group_title );
				// data
				$data = array(
					'text'     => $group_title,
					'children' => array(),
				);
				// convert post objects to post titles
				foreach ( array_keys( $posts ) as $post_id ) {
					$posts[ $post_id ] = $this->get_post_title( $posts[ $post_id ], $field, $options['post_id'] );
				}
				// order posts by search
				if ( $is_search && empty( $args['orderby'] ) && isset( $args['s'] ) ) {
					$posts = acf_order_by_search( $posts, $args['s'] );
				}
				// append to $data
				foreach ( array_keys( $posts ) as $post_id ) {
					$data['children'][] = $this->get_post_result( $post_id, $posts[ $post_id ] );
				}
				// append to $results
				$results[] = $data;
			}
			// add as optgroup or results
			if ( count( $args['post_type'] ) == 1 ) {
				$results = $results[0]['children'];
			}
			// vars
			$response = array(
				'results' => $results,
				'limit'   => $args['posts_per_page'],
			);
			// return
			return $response;
		}
		/*
		*  get_post_result
		*
		*  This function will return an array containing id, text and maybe description data
		*
		*  @type    function
		*  @date    7/07/2016
		*  @since   5.4.0
		*
		*  @param   $id (mixed)
		*  @param   $text (string)
		*  @return  (array)
		*/
		function get_post_result( $id, $text ) {
			// vars
			$result = array(
				'id'   => $id,
				'text' => $text,
			);
			// return
			return $result;
		}
		/*
		*  get_post_title
		*
		*  This function returns the HTML for a result
		*
		*  @type    function
		*  @date    1/11/2013
		*  @since   5.0.0
		*
		*  @param   $post (object)
		*  @param   $field (array)
		*  @param   $post_id (int) the post_id to which this value is saved to
		*  @return  (string)
		*/
		function get_post_title( $post, $field, $post_id = 0, $is_search = 0 ) {
			// get post_id
			if ( ! $post_id ) {
				$post_id = acf_get_form_data( 'post_id' );
			}
			// vars
			$title = acf_get_post_title( $post, $is_search );
			// featured_image
			if ( acf_in_array( 'featured_image', $field['elements'] ) ) {
				// vars
				$class     = 'thumbnail';
				$thumbnail = acf_get_post_thumbnail( $post->ID, array( 17, 17 ) );
				// icon
				if ( $thumbnail['type'] == 'icon' ) {
					$class .= ' -' . $thumbnail['type'];
				}
				// append
				$title = '
' . $thumbnail['html'] . '
' . $title;
			}
			// filters
			$title = apply_filters( 'acf/fields/relationship/result', $title, $post, $field, $post_id );
			$title = apply_filters( 'acf/fields/relationship/result/name=' . $field['_name'], $title, $post, $field, $post_id );
			$title = apply_filters( 'acf/fields/relationship/result/key=' . $field['key'], $title, $post, $field, $post_id );
			// return
			return $title;
		}
		/*
		*  render_field()
		*
		*  Create the HTML interface for your field
		*
		*  @param   $field - an array holding all the field's data
		*
		*  @type    action
		*  @since   3.6
		*  @date    23/01/13
		*/
		function render_field( $field ) {
			// vars
			$post_type = acf_get_array( $field['post_type'] );
			$taxonomy  = acf_get_array( $field['taxonomy'] );
			$filters   = acf_get_array( $field['filters'] );
			// filters
			$filter_count             = count( $filters );
			$filter_post_type_choices = array();
			$filter_taxonomy_choices  = array();
			// post_type filter
			if ( in_array( 'post_type', $filters ) ) {
				$filter_post_type_choices = array(
					'' => __( 'Select post type', 'acf' ),
				) + acf_get_pretty_post_types( $post_type );
			}
			// taxonomy filter
			if ( in_array( 'taxonomy', $filters ) ) {
				$term_choices            = array();
				$filter_taxonomy_choices = array(
					'' => __( 'Select taxonomy', 'acf' ),
				);
				// check for specific taxonomy setting
				if ( $taxonomy ) {
					$terms        = acf_get_encoded_terms( $taxonomy );
					$term_choices = acf_get_choices_from_terms( $terms, 'slug' );
					// if no terms were specified, find all terms
				} else {
					// restrict taxonomies by the post_type selected
					$term_args = array();
					if ( $post_type ) {
						$term_args['taxonomy'] = acf_get_taxonomies(
							array(
								'post_type' => $post_type,
							)
						);
					}
					// get terms
					$terms        = acf_get_grouped_terms( $term_args );
					$term_choices = acf_get_choices_from_grouped_terms( $terms, 'slug' );
				}
				// append term choices
				$filter_taxonomy_choices = $filter_taxonomy_choices + $term_choices;
			}
			// div attributes
			$atts = array(
				'id'             => $field['id'],
				'class'          => "acf-relationship {$field['class']}",
				'data-min'       => $field['min'],
				'data-max'       => $field['max'],
				'data-s'         => '',
				'data-paged'     => 1,
				'data-post_type' => '',
				'data-taxonomy'  => '',
			);
			?>
>
	
			 $field['name'],
					'value' => '',
				)
			);
			?>
	
			
	
				
		
					 __( 'Search...', 'acf' ),
							'data-filter' => 's',
						)
					);
					?>
		
					
		
					 $filter_post_type_choices,
							'data-filter' => 'post_type',
						)
					);
					?>
		
					
		
					 $filter_taxonomy_choices,
							'data-filter' => 'taxonomy',
						)
					);
					?>
		
						
	 
			
	
	
		
		
			
				 $field['value'],
							'post_type' => $field['post_type'],
						)
					);
						// loop
					foreach ( $posts as $post ) :
						?>
					- 
						 $field['name'] . '[]',
									'value' => $post->ID,
								)
							);
						?>
						
								get_post_title( $post, $field ) ); ?>