[Description]
Check whether the current article is topped. Returns TRUE or FALSE.
[Usage]
<? Php is_sticky ($ post_ID);?>
[Parameters]
$ Post_ID
(String) (optional) Article ID
Default value: None
Return value
(Boolean)
True, or false.
[Example]
Is_sticky ();
// Any top post is displayed.
Is_sticky ('17 ');
// When the ID is 17, the article is displayed.
[Source file]
Is_sticky () is located in wp-receivdes/post. php.
/**
* Check if post is sticky.
*
* Sticky posts shoshould remain at the top of The Loop. If the post ID is not
* Given, then The Loop ID for the current post will be used.
*
* @ Since 2.7.0
*
* @ Param int $ post_id Optional. Post ID.
* @ Return bool Whether post is sticky.
*/
Function is_sticky ($ post_id = 0 ){
$ Post_id = absint ($ post_id );
If (! $ Post_id)
$ Post_id = get_the_ID ();
$ Stickies = get_option ('sticky _ posts ');
If (! Is_array ($ stickies ))
Return false;
If (in_array ($ post_id, $ stickies ))
Return true;
Return false;
}
The following is an example:
Is_sticky (10) is used to determine whether an article with $ post_id 10 is a top article, rather than a top article with post_id 10 in all top articles. The reason for the latter's misunderstanding is that I read the official introduction to the is_sticky ($ post_id) method usage document, which is rather vague, this judgment is redundant, and $ post-> id = 10 or get_the_id () = 10 determine whether the current article $ post_id is equal to 10!
Here, I would like to thank tiandi in my friend chain for reminding me that the parameter "is_sticky ($ post_ID) is invalid" does not exist in my message on this site. I want to correct my opinion on wordpress is_sticky ($ post_id) method error.