acf_get_post_id_info()
acf_get_post_id_info
This function will return the type and id for a given $post_id string
Хуки из функции
Возвращает
$info
. (array)
Использование
acf_get_post_id_info( $post_id );
- $post_id **
- -
Список изменений
С версии 5.4.0 | Введена. |
Код acf_get_post_id_info() acf get post id info ACF 6.0.4
function acf_get_post_id_info( $post_id = 0 ) { // vars $info = array( 'type' => 'post', 'id' => 0, ); // bail early if no $post_id if ( ! $post_id ) { return $info; } // check cache // - this function will most likely be called multiple times (saving loading fields from post) // $cache_key = "get_post_id_info/post_id={$post_id}"; // if( acf_isset_cache($cache_key) ) return acf_get_cache($cache_key); // numeric if ( is_numeric( $post_id ) ) { $info['id'] = (int) $post_id; // string } elseif ( is_string( $post_id ) ) { // vars $glue = '_'; $type = explode( $glue, $post_id ); $id = array_pop( $type ); $type = implode( $glue, $type ); $meta = array( 'post', 'user', 'comment', 'term' ); // check if is taxonomy (ACF < 5.5) // - avoid scenario where taxonomy exists with name of meta type if ( ! in_array( $type, $meta ) && acf_isset_termmeta( $type ) ) { $type = 'term'; } // meta if ( is_numeric( $id ) && in_array( $type, $meta ) ) { $info['type'] = $type; $info['id'] = (int) $id; // option } else { $info['type'] = 'option'; $info['id'] = $post_id; } } // update cache // acf_set_cache($cache_key, $info); // filter $info = apply_filters( 'acf/get_post_id_info', $info, $post_id ); // return return $info; }