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.
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