acf_field_taxonomy::load_valuepublicACF 3.6

This filter is appied to the $value after it is loaded from the db

Method of the class: acf_field_taxonomy{}

No Hooks.

Returns

$value. - the value to be saved in te database

Usage

$acf_field_taxonomy = new acf_field_taxonomy();
$acf_field_taxonomy->load_value( $value, $post_id, $field );
$value(required)
.
$post_id(required)
.
$field(required)
.

Changelog

Since 3.6 Introduced.

acf_field_taxonomy::load_value() code ACF 6.0.4

function load_value( $value, $post_id, $field ) {

	// get valid terms
	$value = acf_get_valid_terms( $value, $field['taxonomy'] );

	// load_terms
	if ( $field['load_terms'] ) {

		// Decode $post_id for $type and $id.
		$decoded = acf_decode_post_id( $post_id );
		$type    = $decoded['type'];
		$id      = $decoded['id'];

		if ( $type === 'block' ) {
			// Get parent block...
		}

		// get terms
		$term_ids = wp_get_object_terms(
			$id,
			$field['taxonomy'],
			array(
				'fields'  => 'ids',
				'orderby' => 'none',
			)
		);

		// bail early if no terms
		if ( empty( $term_ids ) || is_wp_error( $term_ids ) ) {
			return false;
		}

		// sort
		if ( ! empty( $value ) ) {

			$order = array();

			foreach ( $term_ids as $i => $v ) {

				$order[ $i ] = array_search( $v, $value );

			}

			array_multisort( $order, $term_ids );

		}

		// update value
		$value = $term_ids;

	}

	// convert back from array if neccessary
	if ( $field['field_type'] == 'select' || $field['field_type'] == 'radio' ) {

		$value = array_shift( $value );

	}

	// return
	return $value;

}