Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add Recently Updated post count into Published post count WordPress

  • SOLVED

Hi again. :) The code below shows a count of the number of posts that have been published in the last 7 days (168hrs) from my custom post type. I also need it to include posts that have been updated recently, not just the new post published.

// Creates recently updated post count for Grid 100
function get_focus15_post_count_from_last_168h($post_type ='focus15index') {
global $wpdb;

$numposts = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(ID) ".
"FROM {$wpdb->posts} ".
"WHERE ".
"post_status='publish' ".
"AND post_type= %s ".
"AND post_date> %s",
$post_type, date('Y-m-d H:i:s', strtotime('-168 hours'))
)
);
return $numposts;
}

Answers (1)

2014-10-18

Dbranes answers:

Did you try the <em>post_modified</em> field, with for example:

// Creates recently updated post count for Grid 100
function get_focus15_post_count_from_last_168h($post_type ='focus15index') {
global $wpdb;
$from = date('Y-m-d H:i:s', strtotime('-168 hours'));
$numposts = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(ID) ".
"FROM {$wpdb->posts} ".
"WHERE ".
"post_status='publish' ".
"AND post_type= %s ".
"AND ( post_date> %s OR post_modified > %s )",
$post_type, $from, $from
)
);
return $numposts;
}


streetfire comments:

Hi I get a syntax error. Not sure why.


Dbranes comments:

ok, I think there was an extra ")".

Please try the updated answer ;-)


streetfire comments:

Awesome, that does seem to be working now. :) Thanks!