0

I need display last modified date of most recent modified post in out of loop.

2
  • 1
    What have you tried so far? Where do you want to display the date - front end or back end? On what page/archive/content type?
    – WebElaine
    Commented Jan 9, 2020 at 14:15
  • If you haven't seen the top related question then there's a nice answer there too, saving the last modified date in options.
    – Rup
    Commented Jan 9, 2020 at 15:29

1 Answer 1

1

This works for me. Place this in your functions.php file:

function prefix_last_modified_date() { 
  $last_modified_date = null;

  $args = array(
    'post_type'  => 'post', // could be page, or a CPT
    'orderby'    => 'modified',
    'post_count' => 1,
  );

  $last_modified = new WP_Query( $args );

  if ( $last_modified->have_posts() ) {
    $last_modified->the_post();
    $last_modified_date = get_the_modified_date();
  }

  wp_reset_postdata(); 

  return $last_modified_date;
} 

Then you can display the last modified post date anywhere in your theme:

echo prefix_last_modified_date();

0

Your Answer

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

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