I want to print the last edited date of a listing on the listing page

Hello, We are using ExpertHive. I want to print the last edited date of a listing on the listing page. So what We did was just below.

  1. Added the code below in functions.php.
function hp_listing_last_modified_block_shortcode($atts) {
    $atts = shortcode_atts(array(
        'post_type' => 'hp_listing',
        'format' => 'F j, Y',
        'class' => 'custom-adminmodified-date',
    ), $atts, 'hp_listing_last_modified_block');

    $args = array(
        'post_type' => $atts['post_type'],
        'posts_per_page' => 1,
        'orderby' => 'modified',

    $query = new WP_Query($args);

    if ($query->have_posts()) {
        $last_modified = get_the_modified_date($atts['format']);

        $class_attr = '';
        if ($atts['class']) {
            $class_attr = ' class="' . esc_attr($atts['class']) . '"';

        $output = '<div' . $class_attr . '>';
        $output .= 'Verified Availability on ';
        $output .= '<strong>' . $last_modified . '</strong>';
        $output .= '</div>';

        return $output;

    return '';
add_shortcode('hp_listing_last_modified_block', 'hp_listing_last_modified_block_shortcode');
  1. Added the code below in the Listing template.
    [hp_listing_last_modified_block class="custom-adminmodified-date"]

  2. By the way, the expected result should be “last modified date”, but all listings are the same, Only the current date is printed, not the last modified date.

In the admin page, I was able to get the last modification date, so I created a custom column, put in the last modification date value, and made it sorted by newest and oldest. But strangely, I couldn’t get the last modified date from the front page.

Could you please give me a exact snippet?? Thank you in advance.

Sorry, there’s no simple code snippet for this, this requires adding a new block or template part to the listing_view_block and/or listing_view_page template. The shortcode you posted is not required and it seems to be incorrect since it fetches the date of the last modified listing, not the current listing where it’s displayed.

Thank you we do as you say and it works.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.