Get_post () (Get an article)
The Get_post () function can query the information of an article based on its ID, and can also return the current article in the loop.
Usage
Get_post ($post, $output, $filter);
Parameters
$id
(Integer | Object) (optional) Article ID or article object, if blank, is automatically set to the current article.
Default value: null (current article)
$output
(string) (optional) Returns the form of the result, optionally:
- Object: Returns an Article object
- Array_a: Returns an array with a key value
- Array_n: Returns an array without a key value
- Default value: OBJECT
$filter
(string) (optional) Article information filtering method. Refer to the Sanitize_post_field () function specifically.
Default value: Row
return value
(Object | null | Array) Returns the article object, array, or null.
Example
Get an article with an ID of 7 and print out its title:
$post _7 = get_post (7); $title = $post _7->post_title;
Get the article with ID 7 (in array form) and print out its caption:
$post _7 = get_post (7, array_a); $title = $post _7[' post_title '];
Other
This function is located in: wp-includes/post.php and wp-includes/class-wp-atom-server.php
Get category Links
In the development of WordPress, often need to get the link of the classification.
If you know the classification ID, you just need to use the Get_category_link () function to get it directly.
But in the actual situation may only know a little bit of classified information, below I introduce a variety of classification information to obtain classification links method.
Get category links by category ID
It is easier to get the classification link by ID, directly using the Get_category_link () function.
Echo Get_category_link (23);
Get category links by category Alias
To get the classification link according to the classification alias need one more step, first use the Get_category_by_slug () function to obtain the classification according to the alias, and then get the classification link.
Echo Get_category_link (Get_category_by_slug (' tips '));
Get category links by category name
The classification link is obtained according to the classification name, and the principle is similar to that of classification aliases, which is to obtain the classification first and then get the link.
Echo Get_category_link (get_cat_id (' WordPress tutorial '));
The above describes the WordPress in the use of information and classification links to use the function, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.