Check if is Post or Comment
I made a function to display the time since posting an article or comment.
function custom_posted_ago() {
global $post;
global $comment;
if ( get_post_type() ) :
$object_ID = get_the_ID( $post );
$timeDiff = human_time_diff( get_the_time( 'U', $object_ID ), current_time( 'timestamp' ) );
$theTime = 'span' . $timeDiff . '/span';
else :
$object_ID = get_comment_ID( $comment );
$timeDiff = human_time_diff( get_comment_date( 'U', $object_ID ), current_time( 'timestamp' ) );
$theTime = 'span' . $timeDiff . '/span';
endif;
$timeAgo = sprintf( __( '%s ago', 'o2' ), $theTime );
return $timeAgo;
}
But if I place it in a comment, it sends me the data of the post.
How can I correctly formulate my condition?
Topic date conditional-tags Wordpress
Category Web