I want to receive each monday the number of posts that were posted on my site during the week. The first part of the code retrieves the number of posts, and the second part sends me an email with the result of the query.

  $args = array(
        'date_query' => array(
                'year' => date( 'Y' ),
                'week' => date( 'W' ),
    $query = new WP_Query( $args );
    echo $query->found_posts;

    function set_mail_html_content_type() {
    return 'text/html';
add_action('number_of_posts', 10 ,2 );
function number_of_posts($post) {
if(date('D', $timestamp) === 'Mon' && $timestamp = strtotime('midnight')) {
    $to = 'admin@mywebsite.com';
    $subject = 'Number of posts';
    $headers = array(
        'Content-Type: text/html',
        'From: hello@mywebsite.com',  );
    $message = ' There was'$query' posts this week ';

    wp_mail( $to, $subject, $message, 'Content-Type: text/html' ); 


However, when I past it in my functions.php file, I get an error on my site so something is wrong with it but I really can't figure out what. Does someone see something that I should change or improve to make it work ?

Thanks for your help

  • Post the error. – Pieter Goosen Dec 13 '15 at 12:49
  • When I try to open debug.log I get 'can't find symbolic link "debug.log" so I can't view the error message ... – Graham Slick Dec 13 '15 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.