0
 $post_type_obj = get_post_type_object(get_post_type());     
 $time_string = '';                                                    
 if ('post' === $post_type_obj->name || $post_type_obj->has_archive) {

$time_string = '<time class=" published updated date_single" datetime="%1$s">%2$s</time>';
if (get_the_time('U') !== get_the_modified_time('U')) {
    $time_string = '<time class=" published date_single" datetime="%1$s">%2$s</time>';
}
$time_string = sprintf(
    $time_string,
    esc_attr(get_the_date('c')),
    esc_html(get_the_date()),
    esc_attr(get_the_modified_date('c')),
    esc_html(get_the_modified_date()),
);
$time_string = '<a class="" href="' . esc_url(get_permalink()) . '" rel="bookmark">' . $time_string . '</a>'; 

Can someone help, please? this is a metadata of a post exactly is the post date

Fernando
  • 11
  • 5

1 Answers1

0

This error means that $post_type_obj is not an object or that the property does not exist in that object.

Try using \is_object($post_type_obj)

Like this:

   $post_type_obj = get_post_type_object(get_post_type());     
     $time_string = '';                                                    
     if (\is_object($post_type_obj) || 'post' === $post_type_obj->name || $post_type_obj->has_archive) {
    
    $time_string = '<time class=" published updated date_single" datetime="%1$s">%2$s</time>';
    if (get_the_time('U') !== get_the_modified_time('U')) {
        $time_string = '<time class=" published date_single" datetime="%1$s">%2$s</time>';
    }
    $time_string = sprintf(
        $time_string,
        esc_attr(get_the_date('c')),
        esc_html(get_the_date()),
        esc_attr(get_the_modified_date('c')),
        esc_html(get_the_modified_date()),
    );
    $time_string = '<a class="" href="' . esc_url(get_permalink()) . '" rel="bookmark">' . $time_string . '</a>';