Get_post () (Get an article)
the Get_post () function can query the information of an article based on the ID, and return the current article in the loop.
Usage
Get_post ($post, $output, $filter);
Parameters
$id
(Integer | Object) (optional) The article ID or article object, which is automatically set to the current article if it is empty.
Default value: null (current article)
$output
(optional) Returns the form of the result, optionally:
- Object: Returns an article objects
- Array_a: Returns an array with key values
- Array_n: Returns an array with no key values
- Default value: OBJECT
$filter
(optional) Article information filtering method. Specific reference Sanitize_post_field () function.
Default value: Row
return value
(Object | null | Array) Returns the article object, array, or null.
Example
Get an article with ID 7 and print out its title:
$post _7 = get_post (7);
$title = $post _7->post_title;
Get the article (array form) with ID 7 and print out its caption:
$post _7 = get_post (7, array_a);
$title = $post _7[' post_title '];
Other
This function is located at: wp-includes/post.php and wp-includes/class-wp-atom-server.php
Get category Links
in WordPress development, often need to get the classification of links.
Knowing the category ID only needs to be obtained directly using the Get_category_link () function.
But in the actual situation may only know a little classification information, below I introduce a variety of classification information to get the classification of the link method.
Get category links based on category ID
It is simpler to get the category link based on the ID, directly using the Get_category_link () function.
Echo Get_category_link (23);
Get the category link based on the category alias
Getting the category link based on the category alias requires one more step, first using the Get_category_by_slug () function to get the taxonomy based on the alias, and then getting the category link.
Echo Get_category_link (Get_category_by_slug (' tips '));
Get category links by category name
According to the category name to get the category link and according to the category alias to get the principle of similar, are to get the category, and then get the link.
Echo Get_category_link (get_cat_id (' WordPress tutorial '));