The actual question is how to create a counter for new posts for a certain time (per hour or per day) on a Wordpress blog. So that you can place it in the site menu. Thank you very much in advance :)

I found this code, as I understand it, it needs to be placed in the functions.php file, but I don’t understand how to add displays of the counter itself to the menu.

$posts= get_posts(array(
                'numberposts' => -1,
                'post_status' => 'publish',
                'orderby' => 'date',
                'order'   => 'DESC',
                'date_query'    => array(
                    'column'  => 'post_date',
                    'after'   => '-7 days'  // -7 Means last 7 days 

When I add this code to the menu it always shows 0:

<h3>Post Count: <?php echo count($posts); ?></h3>

Tell me how to fix this?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.