src/properties/class-papi-property-relationship.php
public function format_value( $values, $slug, $post_id ) {
		if ( is_array( $values ) || is_object( $values ) ) {
			$items  = $this->get_setting( 'items' );
			$result = [];

			foreach ( $values as $id ) {
				// Backwards compatibility with array `id` and `id`.
				$id = is_object( $id ) ? $id->id : $id;
				$id = is_array( $id ) ? $id['id'] : $id;

				if ( empty( $id ) ) {
					continue;
				}

				if ( papi_is_empty( $items ) ) {
					if ( empty( $this->get_setting( 'meta_key' ) ) ) {
						$post = get_post( $id );
					} else {
						$args = [
							'fields'         => 'ids',
							'meta_key'       => $this->get_setting( 'meta_key' ),
							'meta_value'     => $id,
							'posts_per_page' => 1,
							'post_type'      => $this->get_setting( 'post_type' ),
						];

						$query = new WP_Query( $args );

						if ( ! empty( $query->posts ) ) {
							$post = get_post( $query->posts[0] );
						}
					}

					if ( empty( $post ) ) {
						continue;
					}

					$result[] = $post;
				} else {
					$id   = (int) $id;
					$item = null;

					foreach ( (array) $items as $value ) {
						$ids = wp_list_pluck( [$value], 'id' );
						$ids = count( $ids ) > 0 ? strval( $ids[0] ) : '';

						if ( $ids === (string) $id ) {
							$item = $value;
							break;
						}
					}

					if ( is_array( $item ) || is_object( $item ) ) {
						$result[] = papi_maybe_convert_to_object( $item );
					}
				}
			}

			$values = $this->sort_value( $result, $slug, $post_id );

			// Allow only id to be returned.
			if ( ! papi_is_admin() && $this->get_setting( 'fields' ) === 'ids' ) {
				return array_map( function ( $item ) {
					if ( $id = $this->get_post_value( $item ) ) {
						return $id;
					}

					$id = $item->ID;

					if ( is_numeric( $id ) ) {
						return $id == (int) $id ? (int) $id : (float) $id; // loose comparison
					}

					return $id;
				}, $values );
			}

			return $values;
		}

		return $this->default_value;
	}
public function format_value( $values, $slug, $post_id ) {
		if ( is_array( $values ) || is_object( $values ) ) {
			$items  = $this->get_setting( 'items' );
			$result = [];

			foreach ( $values as $id ) {
				// Backwards compatibility with array `id` and `id`.
				$id = is_object( $id ) ? $id->id : $id;
				$id = is_array( $id ) ? $id['id'] : $id;

				if ( empty( $id ) ) {
					continue;
				}

				if ( papi_is_empty( $items ) ) {
					if ( empty( $this->get_setting( 'meta_key' ) ) ) {
						$post = get_post( $id );
					} else {
						$args = [
							'fields'         => 'ids',
							'meta_key'       => $this->get_setting( 'meta_key' ),
							'meta_value'     => $id,
							'posts_per_page' => 1,
							'post_type'      => $this->get_setting( 'post_type' ),
						];

						$query = new WP_Query( $args );

						if ( ! empty( $query->posts ) ) {
							$post = get_post( $query->posts[0] );
						}
					}

					if ( empty( $post ) ) {
						continue;
					}

					$result[] = $post;
				} else {
					$id   = (int) $id;
					$item = null;

					foreach ( (array) $items as $value ) {
						$ids = wp_list_pluck( [$value], 'id' );
						$ids = count( $ids ) > 0 ? strval( $ids[0] ) : '';

						if ( $ids === (string) $id ) {
							$item = $value;
							break;
						}
					}

					if ( is_array( $item ) || is_object( $item ) ) {
						$result[] = papi_maybe_convert_to_object( $item );
					}
				}
			}

			$values = $this->sort_value( $result, $slug, $post_id );

			// Allow only id to be returned.
			if ( ! papi_is_admin() && $this->get_setting( 'fields' ) === 'ids' ) {
				return array_map( function ( $item ) {
					if ( $id = $this->get_post_value( $item ) ) {
						return $id;
					}

					$id = $item->ID;

					if ( is_numeric( $id ) ) {
						return $id == (int) $id ? (int) $id : (float) $id; // loose comparison
					}

					return $id;
				}, $values );
			}

			return $values;
		}

		return $this->default_value;
	}
Format the value of the property before it's returned
to WordPress admin or the site.

@param  mixed  $values
@param  string $slug
@param  int    $post_id

@return array