acf_field_page_link::render_fieldpublicACF 3.6

Renders the Page Link field.

Method of the class: acf_field_page_link{}

No Hooks.

Returns

null. Nothing (null).

Usage

$acf_field_page_link = new acf_field_page_link();
$acf_field_page_link->render_field( $field );
$field(array) (required)
The field settings array.

Changelog

Since 3.6 Introduced.

acf_field_page_link::render_field() code ACF 6.8.8

public function render_field( $field ) {
	// Change Field into a select
	$field['type']    = 'select';
	$field['ui']      = 1;
	$field['ajax']    = 1;
	$field['choices'] = array();
	$field['nonce']   = wp_create_nonce( 'acf_field_' . $this->name . '_' . $field['key'] );

	// populate choices if value exists
	if ( ! empty( $field['value'] ) ) {

		// get posts
		$posts = $this->get_posts( $field['value'], $field );

		// set choices
		if ( ! empty( $posts ) ) {
			foreach ( array_keys( $posts ) as $i ) {

				// vars
				$post = acf_extract_var( $posts, $i );

				if ( is_object( $post ) ) {

					// append to choices
					$field['choices'][ $post->ID ] = $this->get_post_title( $post, $field );
				} else {

					// append to choices
					$field['choices'][ $post ] = $post;
				}
			}
		}
	}

	// render
	acf_render_field( $field );
}