Получает текущий объект запроса (полная информация о посте, метках, рубриках и т.д.).

Эта функция является оберткой для конструкции 

$wp_query->get_queried_object()

Получает текущий объект запроса, например:

  • Если мы на отдельной странице, то вернется объект поста;
  • Если на странице категории, то вернется объект текущей категории;
  • Если на странице автора, то вернется объект с информацией об авторе.

#1 Объект таксономий (метки)

$queried_object = get_queried_object();
print_r( $queried_object );
/* 
вернет:
*/
stdClass Object
(
  [term_id] => 452
  [name] => Метка
  [slug] => metka
  [term_group] => 0
  [term_taxonomy_id] => 452
  [taxonomy] => post_tag
  [description] => 
  [parent] => 0
  [count] => 14
  [filter] => raw
)

#2 Объект поста

$queried_object = get_queried_object();
print_r( $queried_object );
/* 
вернет:
*/
WP_Post Object
(
  [ID] => 2762
  [post_author] => 1
  [post_date] => 2012-09-27 23:25:59
  [post_date_gmt] => 2012-09-27 23:25:59
  [post_content] => Текст поста.
  [post_title] => Заголовок поста
  [post_excerpt] => 
  [post_status] => publish
  [comment_status] => open
  [ping_status] => closed
  [post_password] => 
  [post_name] => zagolovok-posta
  [to_ping] => 
  [pinged] => 
  [post_modified] => 2013-06-10 10:58:25
  [post_modified_gmt] => 2013-06-10 10:58:25
  [post_content_filtered] => 
  [post_parent] => 0
  [guid] => http://wptest.ru/zagolovok-posta
  [menu_order] => 0
  [post_type] => post
  [post_mime_type] => 
  [comment_count] => 0
  [filter] => raw
)

#3 Объект автора

WP_User Object
(
  [data] => stdClass Object
    (
      [ID] => 1
      [user_login] => kama
      [user_pass] => $P$B/spPGtZwp7IPd/FuTORIpu95BZyqW/
      [user_nicename] => kama
      [user_email] => lkj@mail.ru
      [user_url] => 
      [user_registered] => 2011-04-05 15:22:38
      [user_activation_key] => 
      [user_status] => 0
      [display_name] => kama
    )
  [ID] => 1
  [caps] => Array
    (
      [administrator] => 1
    )
  [cap_key] => wp_capabilities
  [roles] => Array
    (
      [0] => administrator
    )
  [allcaps] => Array
    (
      [switch_themes] => 1
      [edit_themes] => 1
      [activate_plugins] => 1
      [edit_plugins] => 1
      [edit_users] => 1
      [edit_files] => 1
      [manage_options] => 1
      [moderate_comments] => 1
      [manage_categories] => 1
      [manage_links] => 1
      [upload_files] => 1
      [import] => 1
      [unfiltered_html] => 1
      [edit_posts] => 1
      [edit_others_posts] => 1
      [edit_published_posts] => 1
      [publish_posts] => 1
      [edit_pages] => 1
      [read] => 1
      [level_10] => 1
      [level_9] => 1
      [level_8] => 1
      [level_7] => 1
      [level_6] => 1
      [level_5] => 1
      [level_4] => 1
      [level_3] => 1
      [level_2] => 1
      [level_1] => 1
      [level_0] => 1
      [edit_others_pages] => 1
      [edit_published_pages] => 1
      [publish_pages] => 1
      [delete_pages] => 1
      [delete_others_pages] => 1
      [delete_published_pages] => 1
      [delete_posts] => 1
      [delete_others_posts] => 1
      [delete_published_posts] => 1
      [delete_private_posts] => 1
      [edit_private_posts] => 1
      [read_private_posts] => 1
      [delete_private_pages] => 1
      [edit_private_pages] => 1
      [read_private_pages] => 1
      [delete_users] => 1
      [create_users] => 1
      [unfiltered_upload] => 1
      [edit_dashboard] => 1
      [update_plugins] => 1
      [delete_plugins] => 1
      [install_plugins] => 1
      [update_themes] => 1
      [install_themes] => 1
      [update_core] => 1
      [list_users] => 1
      [remove_users] => 1
      [add_users] => 1
      [promote_users] => 1
      [edit_theme_options] => 1
      [delete_themes] => 1
      [export] => 1
      [administrator] => 1
    )
  [filter] => 
)

#4 Объект архива типа записи

 stdClass Object
(
  [labels] => stdClass Object
    (
      [name] => Радиостанции
      [singular_name] => Радио
      [add_new] => Добавить радио
      [add_new_item] => Добавление радио
      [edit_item] => Редактировать радио
      [new_item] => Радио
      [view_item] => Смотреть страницу радио
      [search_items] => Искать радио
      [not_found] => Радио не найдено
      [not_found_in_trash] => Радио не найдено
      [parent_item_colon] => 
      [all_items] => Радио
      [archives] => Радио
      [insert_into_item] => Вставить в запись
      [uploaded_to_this_item] => Загруженные для этой записи
      [featured_image] => Миниатюра записи
      [set_featured_image] => Задать миниатюру
      [remove_featured_image] => Удалить миниатюру
      [use_featured_image] => Использовать как миниатюру
      [filter_items_list] => Фильтровать список записей
      [items_list_navigation] => Навигация по списку записей
      [items_list] => Список записей
      [menu_name] => Радио
      [name_admin_bar] => Радио
    )
  [description] => 
  [public] => 1
  [hierarchical] => 
  [exclude_from_search] => 
  [publicly_queryable] => 1
  [show_ui] => 1
  [show_in_menu] => 1
  [show_in_nav_menus] => 1
  [show_in_admin_bar] => 1
  [menu_position] => 5
  [menu_icon] => dashicons-format-audio
  [capability_type] => post
  [map_meta_cap] => 1
  [register_meta_box_cb] => 
  [taxonomies] => Array
    (
      [0] => radio_cat
    )
  [has_archive] => 1
  [rewrite] => Array
    (
      [slug] => radio
      [with_front] => 1
      [pages] => 1
      [feeds] => 1
      [ep_mask] => 1
    )
  [query_var] => radio
  [can_export] => 1
  [delete_with_user] => 
  [_builtin] => 
  [_edit_link] => post.php?post=%d
  [name] => radio
  [cap] => stdClass Object
    (
      [edit_post] => edit_post
      [read_post] => read_post
      [delete_post] => delete_post
      [edit_posts] => edit_posts
      [edit_others_posts] => edit_others_posts
      [publish_posts] => publish_posts
      [read_private_posts] => read_private_posts
      [read] => read
      [delete_posts] => delete_posts
      [delete_private_posts] => delete_private_posts
      [delete_published_posts] => delete_published_posts
      [delete_others_posts] => delete_others_posts
      [edit_private_posts] => edit_private_posts
      [edit_published_posts] => edit_published_posts
      [create_posts] => edit_posts
    )
  [label] => Радиостанции
)

#5 Получим ID страницы записи

$post_id = get_queried_object()->ID;

Источник WP-KAMA