WordPress.org

Forums

WP REST API (WP API)
How to add Comment_count in posts data. (2 posts)

  1. ingenioustechie
    Member
    Posted 1 year ago #

    Hi,
    I'am fetching posts for a certain category, but in the result there is no comment_count. How do I include in each post.

    P.S. Newbie to WordPress.

    https://wordpress.org/plugins/json-rest-api/

  2. aryanduntley
    Member
    Posted 1 year ago #

    Try this:

    function playWithMeta($postray, $postdat, $context){
    	 $morestuff = array("comment_counts" => wp_count_comments($postdat['ID']));
         return array_merge($postray, $morestuff);
    }
    add_filter( 'json_prepare_post', 'playWithMeta' ,10, 3 );

    http://codex.wordpress.org/Function_Reference/wp_count_comments

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP REST API (WP API)
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic