admin管理员组文章数量:1406944
this is my code, and the result shows always the total number of comments instead of number of comments after 12 february 2020.
I don't know why it does not working.
#!/usr/bin/php
<?php
if ( ! defined('ABSPATH') ) {
/** Set up WordPress environment */
require_once( dirname( __FILE__ ) . '/wp-load.php' );
}
$args1 = array(
'status' => 'approve',
'date_query' => array(
array (
'after' => '2020-02-12 10:00:00',
),
),
);
$comments = new WP_Comment_Query( $args1 );
$comms = get_comments( $comments );
$nbr = count( $comms );
echo "$nbr"
?>
thank you for your help
this is my code, and the result shows always the total number of comments instead of number of comments after 12 february 2020.
I don't know why it does not working.
#!/usr/bin/php
<?php
if ( ! defined('ABSPATH') ) {
/** Set up WordPress environment */
require_once( dirname( __FILE__ ) . '/wp-load.php' );
}
$args1 = array(
'status' => 'approve',
'date_query' => array(
array (
'after' => '2020-02-12 10:00:00',
),
),
);
$comments = new WP_Comment_Query( $args1 );
$comms = get_comments( $comments );
$nbr = count( $comms );
echo "$nbr"
?>
thank you for your help
Share Improve this question edited Feb 26, 2020 at 11:49 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Feb 26, 2020 at 11:40 Njaka Eric RavoavyNjaka Eric Ravoavy 11 bronze badge 5 |1 Answer
Reset to default 0thank you for WebElain to help me. This answer driving me to the right request.
Now it's ok. It is an object indead and I use something more simple with get_comments () query with parameter count enabled.
the final code is like this :
#!/usr/bin/php
<?php
if ( ! defined('ABSPATH') ) {
/** Set up WordPress environment */
require_once( dirname( __FILE__ ). '/wordpress/wp-load.php' );
}
$output = shell_exec('date --date="10 day ago" "+%Y-%m-%d %T"');
echo "$output";
// WP_Comment_Query arguments
$args1 = array(
'status' => 'approve',
'count' => true,
'date_query' => array(
array (
'after' => $output,
),
),
);
//$comms = var_dump( $comments );
$nbr = get_comments( $args1 );
echo "$nbr\n";
?>
Thank you.
本文标签: I would like to count number of comments after 5 days ago
版权声明:本文标题:I would like to count number of comments after 5 days ago 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744706858a2620890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_comments()
. Once you've done your initialWP_Comment_Query()
you should have just the comments you need, in an array. Try avar_dump($comments)
to see. If you're then passing those comments intoget_comments()
it's likelyget_comments()
isn't recognizing them as an argument and so you get all comments instead. – WebElaine Commented Feb 26, 2020 at 15:24count($comments)
– WebElaine Commented Feb 26, 2020 at 20:07