^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_post_type()用法示例

get_post_type( int|WP_Post|null $post = null )

Retrieves the post type of the current post or of a given post.


描述


参数

$post

(int|WP_Post|null)
(Optional)
Post ID or post object. Default is global $post.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

Default value: null


返回值

(string|false) Post type on success, false on failure.


源代码

File: wp-includes/post.php

function get_post_type( $post = null ) {
	if ( $post = get_post( $post ) )
		return $post->post_type;

	return false;
}

更新日志

Version 描述
2.1.0 Introduced.

相关函数

Uses

  • wp-includes/post.php:
    get_post()

Used By

  • wp-includes/widgets/class-wp-widget-media.php:
    WP_Widget_Media::has_content()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::has_published_pages()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::find_changeset_post_id()
  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:
    WP_REST_Attachments_Controller::create_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:
    WP_REST_Attachments_Controller::update_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::prepare_item_for_database()
  • wp-includes/class-wp-customize-nav-menus.php:
    WP_Customize_Nav_Menus::save_nav_menus_created_posts()
  • wp-includes/embed.php:
    get_oembed_response_data_rich()
  • wp-admin/includes/media.php:
    get_media_item()
  • wp-admin/includes/post.php:
    bulk_edit_posts()
  • wp-admin/includes/nav-menu.php:
    _wp_ajax_menu_quick_search()
  • wp-includes/capabilities.php:
    map_meta_cap()
  • wp-includes/category-template.php:
    get_the_category_list()
  • wp-includes/class-wp-theme.php:
    WP_Theme::get_page_templates()
  • wp-includes/post.php:
    wp_check_for_changed_slugs()
  • wp-includes/post.php:
    wp_set_post_categories()
  • wp-includes/nav-menu.php:
    is_nav_menu_item()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::_insert_post()
  • Show 13 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 3You must log in to vote on the helpfulness of this note

    Contributed by simonrcodrington

    Default WordPress Post Type Names
    Here are the default post type names. Use these as the parameter for this function to collect the post type object

    • post
    • page
    • attachment
    • revision
    • nav_menu_item
  2. Display the post type. This example needs to be inside the loop.

    
    printf( __( 'The post type is: %s', 'textdomain' ), get_post_type( get_the_ID() ) );
    

    Conditional sentence to see if it is a post type.

    
    if ( get_post_type( get_the_ID() ) == 'slug_post_type' ) {
        //if is true
    }
    

    get_post_type();
    is commonly used in conjunction with Post Formats.
    Functionality is extended in themes by including:
    add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
    in your functions.php file.

    After including this in your theme’s functions.php file, the option to choose a post type (that you included inside the array) will appear in the right sidebar when creating/editing a post.

    If no Post Type is selected, WordPress selects the default which is Standard.

    WordPress supported post formats (that are not defaults) are:
    'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'

    Everything you need to know about using & styling Post Formats is here: https://codex.wordpress.org/Post_Formats

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈