This is that classic question, do you have 6 eggs or half a dozen, and frankly, it doesn’t actually matter.
It is however better to use get_comments_number()
because
-
the post object is retrieved from the
$GLOBALS['post']
global which is set bythe_post()
inside the loop -
the post object is validated through
WP_Post
(throughget_post()
) -
the output from
get_comments_number()
is filterable should you later need to filter the output
Related Posts:
- How to implement a WordPress comments function?
- how to show comments only author which send own posts in wordpress
- I want to change the WordPress comments file
- I need some explanation on global $post [duplicate]
- Should we trust the post globals?
- How to detect single.php (but not single-portfolio.php)?
- Allow variable amount of comments before pagination
- disable WP automatically inserted line breaks after an image
- Getting the post_id in wp_ajax function
- When and Where is `global $post` Set and Available?
- get comments and get posts in loop
- delete post also attachments
- How to call function within a page/post, to dynamically generate content?
- Restrict users from editing post based on the age of the post
- List only child categories a post is in, of a specific parent category
- Can’t show comments count per post outside loop
- Accessing $post variable from template part
- How to change post status from publish to draft using hook in wordpress?
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Only display posts with comments
- How to output comments number of a post per day?
- Force update all posts in custom post type, no content changes
- Disable REST API for a user ROLE
- How to display post tags
- Add confirmation popup on “Move to Trash”
- Allow role to delete posts but block him the wp-admin
- WP_Query in functions.php overrides global $post object, even with wp_reset_query()
- How can I list random authors from current post category?
- Display posts with comments closed, with pagination?
- Disable single post page
- Enabling post thumbnails for custom post type
- Global $post not working in OOP function WordPress
- Getting current post ID in functions.php
- Posts vs. Pages
- Prepend or add an Image to the content of a Post
- Load post attached images on a single page site with fancybox
- How to allow logged in users to post anonymously
- Setting posts_per_page for taxonomy term template
- Change post order random through out the entire WordPress
- How to display the link (title) and thumbnail post?
- Enable Comments Box On Custom Post Type
- How to do set post permalinks using 6 digit random unique function?
- Turn On Comments On Custom Post Types in Directory Theme
- Showing author page if user has no post
- How to assign classes to all elements?
- What do comments with […] mean?
- Show comment number per author per day
- Get all comments of author’s posts
- disable Tab post on nav-menus page (Admin)
- Adding bootstrap classes to video shortcodes
- Every second post different class in blog view
- Hide comments and posts posted by other user
- Get post meta retrieving wrong value
- The_excerpt() doesn’t parse – how to change that?
- How to only publish posts with image in it
- Using system date format
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- Retrieve post in AJAX Callback
- Related Posts: Changing Function For Posts Per Page
- Can WordPress handle following functionalities?
- Same post appears in related Posts?
- How to get post id of last approved comment?
- Help on conditional statement to accompany wp_insert_post function please?
- Set Default Post as Parent Child (Nested) Relation
- Merge get_comments & get_posts into a single query
- get category in list of posts // shortcode for custom related posts
- Alt text attributes not showing over portfolio images
- Set a post expiration and delete a post when expirate
- How to access custom class methods from any include without using global
- Replace Tag Keyword With Link Within Post Content
- Excluding tag Link from html tags in Post content
- Changing a users posts to drafts upon role change
- Get post id outside loop : Notice: Trying to get property of non-object
- Trim excerpt to first paragraph
- im trying make a function to auto correct posts when i open the posts in the backoffice
- How to change number of posts shown on homepage vs other pages?
- Setting a cookie in functions.php and it gets deleted when working on an other function
- Show only top 3 posts from 3 categories in order on home page
- Some comment box wordpress in 1 post [closed]
- How to get posts from network blog
- Get post title by Alphabet
- How can I get a comment ID on Submit?
- Get first comment link on the post itself
- Display only posts with comments
- How can I create a menu items from meta box based on users input
- How to use wp_editor(); in functions.php then retrieve content in the template
- 2 tick boxes appearing below comments
- How *not* to show the last post on the latest posts list
- save_post not working
- wp trim function not working
- How do I access variables outside a function [closed]
- Insert Shortcode exactly at the end of the content
- display last post modified date in genesis child themes
- How can I show the positive and negative comments for a same post separately?
- What function does the loop of displaying posts?
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- Show Next/Previous without Link
- Simple shortcode to check if a user has commented on a certain post
- Filters do not work when there are multiple (one works)
- How to use shortcode to get the second to newest post?