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.
- 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()) {
$query->the_post();
$last_modified = get_the_modified_date($atts['format']);
wp_reset_postdata();
$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');
-
Added the code below in the Listing template.
[hp_listing_last_modified_block class="custom-adminmodified-date"]
-
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.