php - check if the current post is one of the recent 5 post -
i making code in wanted check current post have opened 1 of recent 5 post in word press or not . know current post id can by
get_the_id();
and can check if post exist by
if ( false === get_post_status( $id ) ) { // post not exist } else { // post exists }
but how check value if 1 of recent 5 post or not ? because every , recent post change .
i loop through top 5 posts. check if there match.
function isrecentpost($id) { $recent_posts = wp_get_recent_posts(array('numberposts' => '5')); foreach ($recent_posts $post) { if($post['id'] == $id) { return true; } } return false; }
Comments
Post a Comment