0

I am trying to display in the header of my WordPress site that last time the site was updated.

The last time being defined as the last time either a post or a page was created / modified / deleted

Anyone have any ideas? The only examples I can find are all related to a single page.

2

This is a very simple query of the $wpdb->posts table.

$last_update = $wpdb->get_var("
  SELECT post_date 
  FROM {$wpdb->posts} 
  WHERE post_type IN('post','page') 
  AND post_status = 'publish'
  ORDER BY post_date DESC LIMIT 1"
);
var_dump($last_update);

You could do the same thing (similar) with ...

$args = array(
  'post_type' => array('post','page'),
  'posts_per_page' => 1,
);
$last_updated = new WP_Query($args);
var_dump($last_updated->post->post_date);

... but that may well be overkill just to get the most recent date.

|improve this answer|||||
  • if you leave out post_type won't it search through all types anyway? – Bysander Jul 7 '14 at 14:24

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.