You can specify what kind of comment you want to retrieve using get_comments()
.
// Assumes you've set $post_id somewhere.
$args = array(
'type' => 'trackback',
'post_id' => $post_id,
);
$trackbacks = get_comments( $args );
$trackback_count = count( $trackbacks );
Edited to add: As Sally CJ points out in the comments, you can do this in just one step:
// Assumes you've set $post_id somewhere.
$args = array(
'type' => 'trackback',
'post_id' => $post_id,
'count' => true,
);
$trackback_count = get_comments( $args );
This code is untested but it should provide you a starting place.
As far as being inside/outside The Loop: The above code should work just fine either way, as long as you’ve got a way to get the post ID (get_the_ID()
should work in The Loop; if you’ve got a WP_Post
object called $my_post
, then $my_post->ID
should get it for you).
References
Related Posts:
- How to insert a logo in the header?
- Page template in two level deep folder
- How can I get wp_head() as a string instead of echoing it?
- Returning Variables back into a template
- Check if password protected post is visible
- create-guten-block in wordpress theme?
- Override template file i subfolders
- Single Page theme [closed]
- Template for landing pages
- How to add menù section to my WordPress template?
- Why still output /wp-content/themes/twentynineteen?
- Create theme for mobile phones and tablets only?
- Is there a template tag I can use to link to the archive page corresponding to the month that a post was published on?
- using themename_the_custom_logo() in template-tags?
- What is the point of using the front-page.php template? [closed]
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- WP 3.4 – what action/hook is called when theme customisation is saved?
- Is it good to rename theme folder downloaded from WordPress.org?
- Editing the custom background CSS
- What, specifically, should be included in theme_name_setup()?
- How to get gallery images?
- Is the theme customizer slowing down my site?
- Why does my short code get executed before other content?
- What does “Do not deregister the jquery script in the administration area” mean?
- What is the best book to learn how to make themes for wordpress?
- How can I see what template parts are being called for rendering the viewable page?
- Symlink a directory to wp-content/themes
- What are WooCommerce starter themes? [closed]
- How to disable the gradient and font size internal CSS added by WordPress when using theme.json
- Is there an error in get_the_tag_list()?
- Example of a theme organization without all the default wp files in root
- Disable the Custom Internal CSS added by theme.json for Certain Pages
- Unwanted blank lines before tag
- How do I display the “Archives” widget layout (sidebar) in WordPress by ‘year’ then by ‘months’?
- How do you protect a premium theme from being copied?
- Setting hero/splash section as a blog post
- Where is the correct place(s) in twentysixteen’s header.php to add a Google webfont?
- Custom Nav Walker Displaying Values in Sub Menu
- How to configure wordpress to work with Vuejs with SSR and without hashbang
- How can one update a theme on a live site without interruption?
- Sub folder CSS that’s read by Admin panel
- get_query_var() and permalinks
- Some doubts about how to show posts in a custom theme?
- Toggle Sidebar Display
- Dequeue a style file which is making website load slow!
- Move theme templates to subfolder without losing page associations
- Why are theme templates organized as multiple point of entry PHP files instead of reusing your theme’s index.php?
- Can’t delete theme
- How to add a second stylesheet to the editor
- Can I have two different theme for two different language?
- how to display search term in the template full site editor
- WP_Comment_Query – Get comments and answers separately
- excerpt() shows different result between remote and localhost(development environment)
- Prefix best practice, should we use framework name or theme name?
- Theme Javascript.php Overwritten Nightly [closed]
- How to override p2 breathe theme plugin in content template file?
- How to add Space between sidebar and footer widget in WordPress theme [closed]
- Call to undefined function add_menu_page() on theme activation
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- Best way to develop a new theme on a live site, with new content? [closed]
- How do I make the most minimal vanilla theme possible with nothing but raw content?
- Can I Set Up Session in WordPress Custom Page
- Set a featured image as a replacement to the header image
- Custom theme: How to call archive-post.php for viewing blog posts
- Theme Customizer not displaying saved values in wp_head (CSS)
- How can I hard code my sidebar?
- Thesis -style Navigation
- How can I wrap all blog posts image with
- Issue when posting updates/changes to wordress
- StoreFront WordPress theme: How can i create a new Home page with Custom design same as template [closed]
- A post with a clear:both in its css destroy the theme design, and the sidebar is moved to the bottom
- Never actually adding the action? Or do I have to call the action?
- How to create a WP theme that use BootStrap? [closed]
- How to hide custom sidebar on mobile
- Recommended sidebar / content widths
- Theme Checker Text Domain
- How to copy page/post from one theme to another?
- Not sure how to debug this npm install error. This is a wordpress theme that comes with a built-in gulp/webpack task automation [closed]
- Why front-page.php doesn’t show content of file instead shows loop
- How can I not disable my theme when I want to upload a new version of it?
- Are paginated comments required for publishing Themes?
- How can I fix my theme header for my CSS stylesheet?
- Is hand coding required at all?
- Avoiding do_shortcode() loops
- Creating a Sub Category Template
- Correct was to customise theme using get_theme_mod in scripts
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- Custom theme vs theme customization?
- how can I re-utilize and class on a child theme
- How to figure out which wordpress theme a site was using?
- Incorrect search results in search.php – issue triggered by using `define(‘BodyID’, ‘search’); the_post();` in search.php
- Flexslider not working for my custom theme WordPress
- “No Data Received” error in Chrome every time i try to update the theme functions file
- Redirect to custom login page
- How to close open divs in post loop
- Display Today’s date outside the loop?
- Confused on loading page content
- Turning WordPress Into full-featured website?
- Why am I getting posts back when I shouldnt
- Full site editing templates folder vs block-templates