get_post( int|WP_Post|null $post = null, string $output = OBJECT, string $filter = 'raw' )
Retrieves post data given a post ID or post object.
Description #Description
See sanitize_post() for optional $filter values. Also, the parameter $post
, must be given as a variable, since it is passed by reference.
Parameters #Parameters
- $post
-
(int|WP_Post|null) (Optional) Post ID or post object. Defaults to global $post.
Default value: null
- $output
-
(string) (Optional) The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Post object, an associative array, or a numeric array, respectively.
Default value: OBJECT
- $filter
-
(string) (Optional) Type of filter to apply. Accepts 'raw', 'edit', 'db', or 'display'.
Default value: 'raw'
Return #Return
(WP_Post|array|null) Type corresponding to $output on success or null on failure. When $output is OBJECT, a WP_Post
instance is returned.
Source #Source
File: wp-includes/post.php
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { if ( empty ( $post ) && isset( $GLOBALS [ 'post' ] ) ) { $post = $GLOBALS [ 'post' ]; } if ( $post instanceof WP_Post ) { $_post = $post ; } elseif ( is_object ( $post ) ) { if ( empty ( $post ->filter ) ) { $_post = sanitize_post( $post , 'raw' ); $_post = new WP_Post( $_post ); } elseif ( 'raw' == $post ->filter ) { $_post = new WP_Post( $post ); } else { $_post = WP_Post::get_instance( $post ->ID ); } } else { $_post = WP_Post::get_instance( $post ); } if ( ! $_post ) { return null; } $_post = $_post ->filter( $filter ); if ( $output == ARRAY_A ) { return $_post ->to_array(); } elseif ( $output == ARRAY_N ) { return array_values ( $_post ->to_array() ); } return $_post ; } |
Expand full source code Collapse full source code View on Trac
Changelog #Changelog
Version | Description |
---|---|
1.5.1 | Introduced. |
Related #Related
Uses #Uses
Uses | Description |
---|---|
wp-includes/class-wp-post.php: WP_Post::__construct() |
Constructor. |
wp-includes/class-wp-post.php: WP_Post::get_instance() |
Retrieve WP_Post instance. |
wp-includes/post.php: sanitize_post() |
Sanitize every post field. |
Used By #Used By
Used By | Description |
---|---|
wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php: WP_REST_Autosaves_Controller::create_item() |
Creates, updates or deletes an autosave revision. |
wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php: WP_REST_Autosaves_Controller::create_post_autosave() |
Creates autosave for the specified post. |
wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php: WP_REST_Block_Renderer_Controller::get_item_permissions_check() |
Checks if a given request has access to read blocks. |
wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php: WP_REST_Block_Renderer_Controller::get_item() |
Returns block output from block’s registered render_callback. |
wp-includes/rest-api/search/class-wp-rest-post-search-handler.php: WP_REST_Post_Search_Handler::prepare_item() |
Prepares the search result for a given ID. |
wp-includes/rest-api/search/class-wp-rest-post-search-handler.php: WP_REST_Post_Search_Handler::prepare_item_links() |
Prepares links for the search result of a given ID. |
wp-includes/blocks/block.php: render_block_core_block() |
Renders the |
wp-includes/blocks.php: has_blocks() |
Determine whether a post or content string has blocks. |
wp-includes/blocks.php: has_block() |
Determine whether a $post or a string contains a specific block type. |
wp-admin/includes/post.php: use_block_editor_for_post() |
Return whether the post can be edited in the block editor. |
wp-includes/user.php: wp_get_user_request_data() |
Return data about a user request. |
wp-admin/includes/misc.php: WP_Privacy_Policy_Content::notice() |
Add a notice with a link to the guide when editing the privacy policy page. |
wp-admin/includes/user.php: _wp_privacy_resend_request() |
Resend an existing request and return the result. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::trash_changeset_post() |
Trash or delete a changeset post. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::check_template() |
Check whether the template is valid for the given post. |
wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php: WP_REST_Revisions_Controller::get_revision() |
Get the revision, if the ID is valid. |
wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php: WP_REST_Revisions_Controller::get_parent() |
Get the parent post, if the ID is valid. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::get_post() |
Get the post, if the ID is valid. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::get_comment() |
Get the comment, if the ID is valid. |
wp-includes/nav-menu.php: _wp_delete_customize_changeset_dependent_auto_drafts() |
Delete auto-draft posts associated with the supplied changeset. |
wp-includes/widgets/class-wp-widget-media-audio.php: WP_Widget_Media_Audio::render_media() |
Render the media on the frontend. |
wp-includes/widgets/class-wp-widget-media-video.php: WP_Widget_Media_Video::render_media() |
Render the media on the frontend. |
wp-includes/widgets/class-wp-widget-media.php: WP_Widget_Media::display_media_state() |
Filters the default media display states for items in the Media list table. |
wp-includes/widgets/class-wp-widget-media.php: WP_Widget_Media::is_attachment_with_mime_type() |
Determine if the supplied attachment is for a valid attachment post with the specified MIME type. |
wp-includes/widgets/class-wp-widget-media-image.php: WP_Widget_Media_Image::render_media() |
Render the media on the frontend. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::_publish_changeset_values() |
Publish changeset values. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save_changeset_post() |
Save the post for the loaded changeset. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::import_theme_starter_content() |
Import theme starter content into the customized state. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::get_changeset_post_data() |
Get the data stored in a changeset post. |
wp-includes/theme.php: wp_update_custom_css_post() |
Update the |
wp-includes/theme.php: wp_get_custom_css_post() |
Fetch the |
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::create_item() |
Creates a single attachment. |
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::update_item() |
Updates a single attachment. |
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::create_item_permissions_check() |
Checks if a given request has access to create an attachment. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::check_read_permission() |
Checks if a post can be read. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::handle_template() |
Sets the template for a post. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_database() |
Prepares a single post for create or update. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::create_item() |
Creates a single post. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::update_item() |
Updates a single post. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::delete_item() |
Deletes a single post. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::check_read_permission() |
Checks if the comment can be read. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::prepare_links() |
Prepares links for the request. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::update_item() |
Updates a comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::get_item_permissions_check() |
Checks if a given request has access to read the comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item_permissions_check() |
Checks if a given request has access to create a comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::get_items_permissions_check() |
Checks if a given request has access to read comments. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::sanitize_nav_menus_created_posts() |
Sanitize post IDs for posts created for nav menu items to be published. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::insert_auto_draft_post() |
Add a new |
wp-includes/customize/class-wp-customize-nav-menu-item-setting.php: WP_Customize_Nav_Menu_Item_Setting::get_original_title() |
Get original title. |
wp-includes/revision.php: _wp_preview_post_thumbnail_filter() |
Filters post thumbnail lookup to set the post thumbnail. |
wp-includes/link-template.php: wp_get_canonical_url() |
Returns the canonical URL for a post. |
wp-includes/post.php: wp_get_attachment_caption() |
Retrieves the caption for an attachment. |
wp-includes/revision.php: _wp_post_revision_data() |
Returns a post array ready to be inserted into the posts table as a post revision. |
wp-includes/post.php: wp_add_trashed_suffix_to_post_name_for_post() |
Adds a trashed suffix for a given post. |
wp-includes/embed.php: get_post_embed_url() |
Retrieves the URL to embed a specific post in an iframe. |
wp-includes/embed.php: get_post_embed_html() |
Retrieves the embed code for a specific post. |
wp-includes/embed.php: get_oembed_response_data() |
Retrieves the oEmbed response data for a given post. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::customize_pane_settings() |
Print JavaScript settings for parent window. |
wp-includes/class-wp-comment.php: WP_Comment::__isset() |
Check whether a non-public property is set. |
wp-includes/class-wp-comment.php: WP_Comment::__get() |
Magic getter. |
wp-includes/comment.php: wp_handle_comment_submission() |
Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form. |
wp-includes/link-template.php: get_preview_post_link() |
Retrieves the URL used for the post preview. |
wp-includes/customize/class-wp-customize-nav-menu-item-setting.php: WP_Customize_Nav_Menu_Item_Setting::value() |
Get the instance data for a given nav_menu_item setting. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::load_available_items_query() |
Performs the post_type and taxonomy queries for loading available menu items. |
wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_title() |
Handles the title column output. |
wp-admin/includes/class-wp-site-icon.php: WP_Site_Icon::create_attachment_object() |
Creates an attachment ‘object’. |
wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::column_parent() |
Handles the parent column output. |
wp-includes/post.php: wp_attachment_is() |
Verifies an attachment is of a given type. |
wp-includes/class-wp-query.php: WP_Query::setup_postdata() |
Set up global post data. |
wp-includes/ms-blogs.php: _update_posts_count_on_delete() |
Handler for updating the current site’s posts count when a post is deleted. |
wp-admin/includes/ajax-actions.php: wp_ajax_parse_embed() |
Apply [embed] Ajax handlers to a string. |
wp-admin/includes/ajax-actions.php: wp_ajax_parse_media_shortcode() | |
wp-admin/includes/class-file-upload-upgrader.php: File_Upload_Upgrader::__construct() |
Construct the upgrader for a form. |
wp-admin/includes/class-wp-screen.php: WP_Screen::get() |
Fetches a screen object. |
wp-admin/includes/export.php: wxr_post_taxonomy() |
Output list of taxonomy terms, in XML tag format, associated with a post |
wp-admin/includes/deprecated.php: get_post_to_edit() |
Gets an existing post and format it for editing. |
wp-admin/includes/image-edit.php: stream_preview_image() |
Streams image in post to browser, along with enqueued changes in $_REQUEST[‘history’] |
wp-admin/includes/image-edit.php: wp_save_image() |
Saves image to post along with enqueued changes in $_REQUEST[‘history’] |
wp-admin/includes/image.php: wp_generate_attachment_metadata() |
Generate post thumbnail attachment meta data. |
wp-admin/includes/dashboard.php: wp_dashboard_quick_press() |
The Quick Draft widget display and creation of drafts. |
wp-admin/includes/template.php: the_post_password() |
Displays the post password. |
wp-admin/includes/template.php: meta_form() |
Prints the form in the Custom Fields meta box. |
wp-admin/includes/template.php: touch_time() |
Print out HTML form date elements for editing post or comment publish date. |
wp-admin/includes/template.php: parent_dropdown() |
Print out option HTML elements for the page parents drop-down. |
wp-admin/includes/template.php: wp_popular_terms_checklist() |
Retrieve a list of the most popular terms from the specified taxonomy. |
wp-admin/includes/media.php: media_upload_flash_bypass() |
Displays the multi-file uploader message. |
wp-admin/includes/media.php: attachment_submitbox_metadata() |
Displays non-editable attachment metadata in the publish meta box. |
wp-admin/includes/media.php: image_media_send_to_editor() |
Retrieves the media element HTML to send to the editor. |
wp-admin/includes/media.php: get_attachment_fields_to_edit() |
Retrieves the attachment fields to edit form fields. |
wp-admin/includes/media.php: get_media_items() |
Retrieve HTML for media items of post gallery. |
wp-admin/includes/media.php: get_media_item() |
Retrieve HTML form for modifying the image attachment. |
wp-admin/includes/media.php: get_compat_media_markup() | |
wp-admin/includes/media.php: media_upload_form_handler() |
Handles form submissions for the legacy media uploader. |
wp-admin/includes/media.php: media_handle_upload() |
Save a file submitted from a POST request and create an attachment post for it. |
wp-admin/includes/media.php: media_handle_sideload() |
Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). |
wp-admin/includes/media.php: media_buttons() |
Adds the media button to the editor |
wp-admin/includes/post.php: get_sample_permalink_html() |
Returns the HTML of the sample permalink slug editor. |
wp-admin/includes/post.php: _wp_post_thumbnail_html() |
Output HTML for the post thumbnail meta-box. |
wp-admin/includes/post.php: wp_check_post_lock() |
Check to see if the post is currently being edited by another user. |
wp-admin/includes/post.php: wp_set_post_lock() |
Mark the post as currently being edited by the current user |
wp-admin/includes/post.php: _admin_notice_post_locked() |
Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. |
wp-admin/includes/post.php: wp_create_post_autosave() |
Creates autosave data for the specified post from $_POST data. |
wp-admin/includes/post.php: post_preview() |
Saves a draft or manually autosaves for the purpose of showing a post preview. |
wp-admin/includes/post.php: wp_autosave() |
Save a post submitted with XHR |
wp-admin/includes/post.php: _fix_attachment_links() |
Replace hrefs of attachment anchors with up-to-date permalinks. |
wp-admin/includes/post.php: get_sample_permalink() |
Get a sample permalink based off of the post name. |
wp-admin/includes/ajax-actions.php: wp_ajax_save_attachment_order() |
Ajax handler for saving the attachment order. |
wp-admin/includes/ajax-actions.php: wp_ajax_send_attachment_to_editor() |
Ajax handler for sending an attachment to the editor. |
wp-admin/includes/ajax-actions.php: wp_ajax_send_link_to_editor() |
Ajax handler for sending a link to the editor. |
wp-admin/includes/ajax-actions.php: wp_ajax_get_revision_diffs() |
Ajax handler for getting revision diffs. |
wp-admin/includes/post.php: edit_post() |
Update an existing post with values provided in $_POST. |
wp-admin/includes/post.php: bulk_edit_posts() |
Process the post data for the bulk editing of posts. |
wp-admin/includes/post.php: get_default_post_to_edit() |
Default post information to use when populating the “Write Post” form. |
wp-admin/includes/ajax-actions.php: wp_ajax_wp_fullscreen_save_post() |
Ajax handler for saving posts from the fullscreen editor. |
wp-admin/includes/ajax-actions.php: wp_ajax_wp_remove_post_lock() |
Ajax handler for removing a post lock. |
wp-admin/includes/ajax-actions.php: wp_ajax_get_attachment() |
Ajax handler for getting an attachment. |
wp-admin/includes/ajax-actions.php: wp_ajax_save_attachment() |
Ajax handler for updating attachment attributes. |
wp-admin/includes/ajax-actions.php: wp_ajax_save_attachment_compat() |
Ajax handler for saving backward compatible attachment attributes. |
wp-admin/includes/ajax-actions.php: wp_ajax_add_menu_item() |
Ajax handler for adding a menu item. |
wp-admin/includes/ajax-actions.php: wp_ajax_add_meta() |
Ajax handler for adding meta. |
wp-admin/includes/ajax-actions.php: wp_ajax_inline_save() |
Ajax handler for Quick Edit saving a post from a list table. |
wp-admin/includes/ajax-actions.php: wp_ajax_delete_post() |
Ajax handler for deleting a post. |
wp-admin/includes/ajax-actions.php: wp_ajax_trash_post() |
Ajax handler for sending a post to the trash. |
wp-admin/includes/ajax-actions.php: wp_ajax_delete_page() |
Ajax handler to delete a page. |
wp-admin/includes/ajax-actions.php: wp_ajax_replyto_comment() |
Ajax handler for replying to a comment. |
wp-admin/includes/revision.php: wp_get_revision_ui_diff() |
Get the revision UI diff. |
wp-admin/includes/revision.php: wp_prepare_revisions_for_js() |
Prepare revisions for JavaScript. |
wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::column_response() | |
wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::single_row() | |
wp-admin/includes/class-walker-nav-menu-edit.php: Walker_Nav_Menu_Edit::start_el() |
Start the element output. |
wp-admin/includes/nav-menu.php: _wp_ajax_menu_quick_search() |
Prints the appropriate response to a menu quick search. |
wp-admin/includes/nav-menu.php: wp_nav_menu_item_post_type_meta_box() |
Displays a meta box for a post type menu item. |
wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::single_row() | |
wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::_page_rows() |
Given a top level page ID, display the nested hierarchy of sub-pages together with paging support |
wp-admin/custom-header.php: Custom_Image_Header::create_attachment_object() |
Create an attachment ‘object’. |
wp-includes/capabilities.php: author_can() |
Whether the author of the supplied post has a specific capability. |
wp-includes/capabilities.php: map_meta_cap() |
Map meta capabilities to primitive capabilities. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save() |
Handle customize_save WP Ajax request to save/update a changeset. |
wp-includes/category-template.php: has_term() |
Check if the current post has any of given terms. |
wp-includes/category-template.php: get_the_terms() |
Retrieve the terms of the taxonomy that are attached to the post. |
wp-includes/pluggable.php: wp_notify_postauthor() |
Notify an author (and/or others) of a comment/trackback/pingback on a post. |
wp-includes/pluggable.php: wp_notify_moderator() |
Notifies the moderator of the site about a new comment that is awaiting approval. |
wp-includes/general-template.php: feed_links_extra() |
Display the links to the extra feeds such as category feeds. |
wp-includes/general-template.php: get_the_modified_date() |
Retrieve the date on which the post was last modified. |
wp-includes/general-template.php: get_the_time() |
Retrieve the time at which the post was written. |
wp-includes/general-template.php: get_post_time() |
Retrieve the time at which the post was written. |
wp-includes/general-template.php: get_the_modified_time() |
Retrieve the time at which the post was last modified. |
wp-includes/general-template.php: get_post_modified_time() |
Retrieve the time at which the post was last modified. |
wp-includes/general-template.php: the_weekday() |
Display the weekday on which the post was written. |
wp-includes/general-template.php: the_weekday_date() |
Display the weekday on which the post was written. |
wp-includes/general-template.php: the_date_xml() |
Outputs the date in iso8601 format for xml files. |
wp-includes/general-template.php: get_the_date() |
Retrieve the date on which the post was written. |
wp-includes/deprecated.php: wp_get_single_post() |
Retrieve a single post, based on post ID. |
wp-includes/deprecated.php: get_parent_post_rel_link() |
Get parent post relational link. |
wp-includes/deprecated.php: get_the_attachment_link() |
Retrieve HTML content of attachment image with link. |
wp-includes/deprecated.php: get_attachment_icon_src() |
Retrieve icon URL and Path. |
wp-includes/deprecated.php: get_attachment_icon() |
Retrieve HTML content of icon attachment image element. |
wp-includes/deprecated.php: get_attachment_innerHTML() |
Retrieve HTML content of image element. |
wp-includes/deprecated.php: user_can_edit_post() |
Whether user can edit a post. |
wp-includes/deprecated.php: get_postdata() |
Retrieves all post data for a given post. |
wp-includes/deprecated.php: start_wp() |
Sets up the WordPress Loop. |
wp-includes/class-wp-query.php: WP_Query::get_queried_object() |
Retrieve queried object. |
wp-includes/class-wp-query.php: WP_Query::get_posts() |
Retrieves an array of posts based on query variables. |
wp-includes/functions.php: wp_scheduled_delete() |
Permanently delete comments or posts of any type that have held a status of ‘trash’ for the number of days defined in EMPTY_TRASH_DAYS. |
wp-includes/class-wp-embed.php: WP_Embed::cache_oembed() |
Triggers a caching of all oEmbed results. |
wp-includes/class-wp-embed.php: WP_Embed::maybe_run_ajax_cache() |
If a post/page was saved, then output JavaScript to make an Ajax request that will call WP_Embed::cache_oembed(). |
wp-includes/class-wp-embed.php: WP_Embed::shortcode() |
The do_shortcode() callback function. |
wp-includes/taxonomy.php: get_the_taxonomies() |
Retrieve all taxonomies associated with a post. |
wp-includes/taxonomy.php: get_post_taxonomies() |
Retrieve all taxonomies of a post with just the names. |
wp-includes/link-template.php: wp_get_shortlink() |
Returns a shortlink for a post, page, attachment, or site. |
wp-includes/link-template.php: the_shortlink() |
Displays the shortlink for a post. |
wp-includes/link-template.php: get_adjacent_post_link() |
Retrieves the adjacent post link. |
wp-includes/link-template.php: get_adjacent_post() |
Retrieves the adjacent post. |
wp-includes/link-template.php: get_adjacent_post_rel_link() |
Retrieves the adjacent post relational link. |
wp-includes/link-template.php: get_boundary_post() |
Retrieves the boundary post. |
wp-includes/link-template.php: get_edit_post_link() |
Retrieves the edit post link for post. |
wp-includes/link-template.php: edit_post_link() |
Displays the edit post link for post. |
wp-includes/link-template.php: get_delete_post_link() |
Retrieves the delete posts link for post. |
wp-includes/link-template.php: get_post_comments_feed_link() |
Retrieves the permalink for the post comments feed. |
wp-includes/link-template.php: permalink_anchor() |
Displays the permalink anchor for the current post. |
wp-includes/link-template.php: get_permalink() |
Retrieves the full permalink for the current post or post ID. |
wp-includes/link-template.php: get_post_permalink() |
Retrieves the permalink for a post of a custom post type. |
wp-includes/link-template.php: get_page_link() |
Retrieves the permalink for the current page or page ID. |
wp-includes/link-template.php: _get_page_link() |
Retrieves the page permalink. |
wp-includes/link-template.php: get_attachment_link() |
Retrieves the permalink for an attachment. |
wp-includes/admin-bar.php: wp_admin_bar_edit_menu() |
Provide an edit link for posts and terms. |
wp-includes/post-thumbnail-template.php: get_post_thumbnail_id() |
Retrieve post thumbnail ID. |
wp-includes/post-thumbnail-template.php: get_the_post_thumbnail() |
Retrieve the post thumbnail. |
wp-includes/class-walker-page.php: Walker_Page::start_el() |
Outputs the beginning of the current element in the tree. |
wp-includes/post-template.php: wp_get_attachment_link() |
Retrieve an attachment page link using an image or icon, if possible. |
wp-includes/post-template.php: prepend_attachment() |
Wrap attachment in paragraph tag before content. |
wp-includes/post-template.php: get_the_password_form() |
Retrieve protected post password form content. |
wp-includes/post-template.php: get_page_template_slug() |
Get the specific template name for a given post. |
wp-includes/post-template.php: wp_post_revision_title() |
Retrieve formatted date timestamp of a revision (linked to that revisions’s page). |
wp-includes/post-template.php: wp_post_revision_title_expanded() |
Retrieve formatted date timestamp of a revision (linked to that revisions’s page). |
wp-includes/post-template.php: wp_list_post_revisions() |
Display a list of a post’s revisions. |
wp-includes/post-template.php: post_password_required() |
Whether post requires password and correct password has been provided. |
wp-includes/post-template.php: _wp_link_page() |
Helper function for wp_link_pages(). |
wp-includes/post-template.php: get_the_guid() |
Retrieve the Post Global Unique Identifier (guid). |
wp-includes/post-template.php: get_the_content() |
Retrieve the post content. |
wp-includes/post-template.php: get_the_excerpt() |
Retrieves the post excerpt. |
wp-includes/post-template.php: has_excerpt() |
Determines whether the post has a custom excerpt. |
wp-includes/post-template.php: get_post_class() |
Retrieves an array of the class names for the post container element. |
wp-includes/post-template.php: get_body_class() |
Retrieves an array of the class names for the body element. |
wp-includes/post-template.php: get_the_ID() |
Retrieve the ID of the current item in the WordPress Loop. |
wp-includes/post-template.php: the_title_attribute() |
Sanitize the current title when retrieving or displaying. |
wp-includes/post-template.php: get_the_title() |
Retrieve post title. |
wp-includes/post-template.php: the_guid() |
Display the Post Global Unique Identifier (guid). |
wp-includes/media.php: get_post_galleries() |
Retrieves galleries from the passed post’s content. |
wp-includes/media.php: wp_prepare_attachment_for_js() |
Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. |
wp-includes/media.php: wp_enqueue_media() |
Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs. |
wp-includes/media.php: get_attached_media() |
Retrieves media attached to the passed post. |
wp-includes/media.php: wp_video_shortcode() |
Builds the Video shortcode output. |
wp-includes/media.php: adjacent_image_link() |
Displays next or previous image link that has the same post parent. |
wp-includes/media.php: get_attachment_taxonomies() |
Retrieves taxonomies attached to given the attachment. |
wp-includes/media.php: gallery_shortcode() |
Builds the Gallery shortcode output. |
wp-includes/media.php: wp_playlist_shortcode() |
Builds the Playlist shortcode output. |
wp-includes/media.php: wp_audio_shortcode() |
Builds the Audio shortcode output. |
wp-includes/media.php: wp_get_attachment_image() |
Get an HTML img element representing an image attachment |
wp-includes/post.php: clean_post_cache() |
Will clean the post in the cache. |
wp-includes/post.php: wp_get_post_parent_id() |
Returns the ID of the post’s parent. |
wp-includes/post.php: set_post_thumbnail() |
Sets the post thumbnail (featured image) for the given post. |
wp-includes/post.php: delete_post_thumbnail() |
Removes the thumbnail (featured image) from the given post. |
wp-includes/post.php: wp_mime_type_icon() |
Retrieve the icon for a MIME type. |
wp-includes/post.php: wp_delete_attachment() |
Trash or delete an attachment. |
wp-includes/post.php: wp_get_attachment_metadata() |
Retrieve attachment meta field for attachment ID. |
wp-includes/post.php: wp_update_attachment_metadata() |
Update metadata for an attachment. |
wp-includes/post.php: wp_get_attachment_url() |
Retrieve the URL for an attachment. |
wp-includes/post.php: wp_get_attachment_thumb_file() |
Retrieve thumbnail for an attachment. |
wp-includes/post.php: wp_get_attachment_thumb_url() |
Retrieve URL for an attachment thumbnail. |
wp-includes/post.php: get_pung() |
Retrieve URLs already pinged for a post. |
wp-includes/post.php: get_to_ping() |
Retrieve URLs that need to be pinged. |
wp-includes/post.php: trackback_url_list() |
Do trackbacks for a list of URLs. |
wp-includes/post.php: get_page() |
Retrieves page data given a page ID or page object. |
wp-includes/post.php: get_page_by_path() |
Retrieves a page given its path. |
wp-includes/post.php: get_page_by_title() |
Retrieve a page given its title. |
wp-includes/post.php: get_page_uri() |
Build the URI path for a page. |
wp-includes/post.php: is_local_attachment() |
Determines whether an attachment URI is local and really an attachment. |
wp-includes/post.php: wp_publish_post() |
Publish a post by transitioning the post status. |
wp-includes/post.php: check_and_publish_future_post() |
Publish future post and make sure post ID has future post status. |
wp-includes/post.php: wp_unique_post_slug() |
Computes a unique slug for the post, when given the desired slug and some post details. |
wp-includes/post.php: add_ping() |
Add a URL to those already pinged. |
wp-includes/post.php: wp_untrash_post_comments() |
Restore comments for a post from the trash. |
wp-includes/post.php: wp_insert_post() |
Insert or update a post. |
wp-includes/post.php: wp_update_post() |
Update a post with new post data. |
wp-includes/post.php: wp_delete_post() |
Trash or delete a post or page. |
wp-includes/post.php: _reset_front_page_settings_for_post() |
Reset the page_on_front, show_on_front, and page_for_post settings when a linked page is deleted or trashed. |
wp-includes/post.php: wp_trash_post() |
Move a post or page to the Trash |
wp-includes/post.php: wp_untrash_post() |
Restore a post or page from the Trash. |
wp-includes/post.php: wp_trash_post_comments() |
Moves comments for a post to the trash. |
wp-includes/post.php: get_post_ancestors() |
Retrieve ancestors of a post. |
wp-includes/post.php: get_post_field() |
Retrieve data from a post field based on Post ID. |
wp-includes/post.php: get_post_mime_type() |
Retrieve the mime type of an attachment based on the ID. |
wp-includes/post.php: get_post_status() |
Retrieve the post status based on the post ID. |
wp-includes/post.php: get_post_type() |
Retrieves the post type of the current post or of a given post. |
wp-includes/post.php: update_attached_file() |
Update attachment file path based on attachment ID. |
wp-includes/rewrite.php: url_to_postid() |
Examine a URL and try to determine the post ID it represents. |
wp-includes/canonical.php: redirect_canonical() |
Redirects incoming links to the proper URL based on the site url. |
wp-includes/revision.php: _wp_put_post_revision() |
Inserts post data into the posts table as a post revision. |
wp-includes/revision.php: wp_get_post_revision() |
Gets a post revision. |
wp-includes/revision.php: wp_get_post_revisions() |
Returns all revisions of specified post. |
wp-includes/revision.php: _wp_preview_terms_filter() |
Filters terms lookup to set the post format. |
wp-includes/revision.php: _wp_post_revision_fields() |
Determines which fields of posts are to be saved in revisions. |
wp-includes/revision.php: wp_save_post_revision() |
Creates a revision for the current version of a post. |
wp-includes/ms-functions.php: get_blog_post() |
Get a blog post from any site on the network. |
wp-includes/post-formats.php: get_post_format() |
Retrieve the format slug for a post |
wp-includes/post-formats.php: set_post_format() |
Assign a format to a post |
wp-includes/author-template.php: get_the_author_posts() |
Retrieve the number of posts by the author of the current post. |
wp-includes/ms-blogs.php: _update_blog_date_on_post_delete() |
Handler for updating the current site’s last updated date when a published post is deleted. |
wp-includes/author-template.php: get_the_modified_author() |
Retrieve the author who last edited the current post. |
wp-includes/nav-menu.php: wp_setup_nav_menu_item() |
Decorates a menu item object with the shared navigation menu item properties. |
wp-includes/nav-menu.php: wp_update_nav_menu_item() |
Save the properties of a menu item or create a new one. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mt_getPostCategories() |
Retrieve post categories. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mt_setPostCategories() |
Sets categories for a post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mt_getTrackbackPings() |
Retrieve trackbacks sent to a given post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mt_publishPost() |
Sets a post’s publish status to ‘publish’. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::pingback_ping() |
Retrieves a pingback and registers it. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::pingback_extensions_getPingbacks() |
Retrieve array of URLs that pingbacked the given URL. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_editPost() |
Edit a post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_getPost() |
Retrieve post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_newMediaObject() |
Uploads a file, following your settings. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::blogger_getPost() |
Retrieve post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::blogger_editPost() |
Edit a post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::blogger_deletePost() |
Remove a post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getMediaItem() |
Retrieve a media item by ID |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getRevisions() |
Retrieve revisions for a specific post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_restoreRevision() |
Restore a post revision |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_newComment() |
Create new comment. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getCommentCount() |
Retrieve comment count. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_deletePage() |
Delete page. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_editPage() |
Edit page. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getPage() |
Retrieve page. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_prepare_page() |
Prepares page data for return in an XML-RPC object. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_insert_post() |
Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_editPost() |
Edit a post for any registered post type. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_deletePost() |
Delete a post for any registered post type. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getPost() |
Retrieve a post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_prepare_post() |
Prepares post data for return in an XML-RPC object. |
wp-includes/class-wp-customize-control.php: WP_Customize_Control::render_content() |
Render the control’s content. |
wp-includes/comment-template.php: get_post_reply_link() |
Retrieve HTML content for reply to post link. |
wp-includes/comment-template.php: comments_open() |
Determines whether the current post is open for comments. |
wp-includes/comment-template.php: pings_open() |
Determines whether the current post is open for pings. |
wp-includes/comment-template.php: wp_comment_form_unfiltered_html_nonce() |
Display form token for unfiltered comments. |
wp-includes/comment-template.php: get_comment_reply_link() |
Retrieve HTML content for reply to comment link. |
wp-includes/comment-template.php: get_comments_number() |
Retrieves the amount of comments a post has. |
wp-includes/comment-template.php: get_comment_class() |
Returns the classes for the comment div as an array. |
wp-includes/comment.php: _close_comments_for_old_post() |
Close comments on an old post. Hooked to comments_open and pings_open. |
wp-includes/comment.php: wp_update_comment() |
Updates an existing comment in the database. |
wp-includes/comment.php: wp_update_comment_count_now() |
Updates the comment count for the post. |
wp-includes/comment.php: do_trackbacks() |
Perform trackbacks. |
wp-includes/comment.php: pingback() |
Pings back the links found in a post. |
wp-includes/class-wp-editor.php: _WP_Editors::editor_settings() |
User Contributed Notes #User Contributed Notes
You must log in before being able to contribute a note or feedback.
For reference, WP_Post OBJECT contains following fields:
WP_Post Object
(
[ID] =>
[post_author] =>
[post_date] =>
[post_date_gmt] =>
[post_content] =>
[post_title] =>
[post_excerpt] =>
[post_status] =>
[comment_status] =>
[ping_status] =>
[post_password] =>
[post_name] =>
[to_ping] =>
[pinged] =>
[post_modified] =>
[post_modified_gmt] =>
[post_content_filtered] =>
[post_parent] =>
[guid] =>
[menu_order] =>
[post_type] =>
[post_mime_type] =>
[comment_count] =>
[filter] =>
)
Expand full source codeCollapse full source code
Wouldn’t it be better practice to use get_the_title(..) in this case? directly accessing the post object’s data member would bypass applying filters and enforcing protected and private settings, unless that’s explicitly desired.
If you need special things—[shortcodes], paragraph tags, anything exciting—in the content, you should apply the filters as opposed to using do_shortcode().
$post
= get_post( 42 );
$output
= apply_filters(
'the_content'
,
$post
->post_content );
To get the title for a post with ID 7:
$post_7
= get_post( 7 );
$title
=
$post_7
->post_title;
Alternatively, specify the $output parameter:
$post_7
= get_post( 7, ARRAY_A );
$title
=
$post_7
[
'post_title'
];
To Get author of the Post
$post_info
= get_post( 10 );
$author
=
$post_info
->post_author;
For Reference : WP_Post Object has following properties, which are returned by get_post().
Member Variable Variable Type Notes
ID int The ID of the post
post_author string The post author's user ID (numeric string)
post_name string The post's slug
post_type string See Post Types
post_title string The title of the post
post_date string Format: 0000-00-00 00:00:00
post_date_gmt string Format: 0000-00-00 00:00:00
post_content string The full content of the post
post_excerpt string User-defined post excerpt
post_status string See get_post_status
for
values
comment_status string Returns: { open, closed }
ping_status string Returns: { open, closed }
post_password string Returns
empty
string
if
no password
post_parent int Parent Post ID (
default
0)
post_modified string Format: 0000-00-00 00:00:00
post_modified_gmt string Format: 0000-00-00 00:00:00
comment_count string Number of comments on post (numeric string)
menu_order string Order value
as
set through page-attribute when enabled (numeric string. Defaults to 0)
Expand full source codeCollapse full source code
If you want to get a post by slug, you could do a new WP_Query, or use the get_page_by_path function: https://developer.wordpress.org/reference/functions/get_page_by_path/
You’ll need to use the post_type if you are not getting a page.
If you have a shortcode in the content you should use:
$post
= get_post( 4304,ARRAY_A );
$output
= do_shortcode(
$post
[
'post_content'
]);