ACF_Internal_Post_Type::get_post_object
Retrieves the WP_Post object for an ACF internal CPT.
Метод класса: ACF_Internal_Post_Type{}
Хуков нет.
Возвращает
WP_Post|boolean. The post object, or false on failure.
Использование
$ACF_Internal_Post_Type = new ACF_Internal_Post_Type(); $ACF_Internal_Post_Type->get_post_object( $id );
- $id(int|строка)
- The post ID, key, or name.
Список изменений
| С версии 6.1 | Введена. |
Код ACF_Internal_Post_Type::get_post_object() ACF Internal Post Type::get post object ACF 6.8.8
public function get_post_object( $id = 0 ) {
if ( is_numeric( $id ) ) {
$post_object = get_post( $id );
if ( $post_object && $post_object->post_type === $this->post_type ) {
return $post_object;
}
return false;
}
if ( is_string( $id ) ) {
// Try cache.
$cache_key = $this->cache_key . $id;
$post_id = wp_cache_get( $cache_key, 'acf' );
if ( $post_id === false ) {
$query_key = 'acf_' . $this->post_key_prefix . 'key';
// Query posts.
$posts = get_posts(
array(
'posts_per_page' => 1,
'post_type' => $this->post_type,
'post_status' => array( 'publish', 'acf-disabled', 'trash' ),
'orderby' => 'menu_order title',
'order' => 'ASC',
'suppress_filters' => false,
'cache_results' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
$query_key => $id, // Used to check post_name for field group/post type/taxonomy key.
)
);
// Update $post_id with a non-false value.
$post_id = $posts ? $posts[0]->ID : 0;
// Update cache.
wp_cache_set( $cache_key, $post_id, 'acf' );
}
// Check $post_id and return the post when possible.
if ( $post_id ) {
return get_post( $post_id );
}
}
return false;
}