Я проверил другие похожие посты, но, к сожалению, это не помогло моей проблеме.
Я получаю
Предупреждение: использование неопределенной константы _ - предполагается '_' (это приведет к ошибке в будущей версии PHP)
ошибка после обновления до PHP версии 7.2
Я проследил причину этого фрагмента кода:
<span class="post-container__excerpt-price"><?php echo '$' . number_format( (float)get_field('price', $post->ID) ); ?></span>
Когда я удаляю это, ошибка исчезает, но я не могу кажется, найти какие-либо явные проблемы с этим кодом либо. 'price', $post->ID
относится к пользовательскому полю, созданному с помощью ACF.
У кого-нибудь есть идеи? Большое спасибо!
Весь блок кода ниже:
// create shortcode to list all listings
add_shortcode( 'list-posts-basic', 'rmcc_post_listing_shortcode1' );
function rmcc_post_listing_shortcode1( $atts ) {
ob_start();
$query = new WP_Query( array(
'post_type' => 'listings',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'date',
) );
if ( $query->have_posts() ) { ?>
<div class="posts-container">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="post-container" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a class="" href="<?php the_permalink(); ?>"><div class="listing-post-img" style="background: url(<?php echo get_the_post_thumbnail_url() ?> )"></div></a>
<div class="post-container__content">
<a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
<p class="post-container__excerpt">
<?php the_excerpt(); ?>
<span class="post-container__excerpt-price"><?php echo '$' . number_format( (float)get_field('price', $post->ID) ); ?></span>
</p>
<a class="post-container__button" href="<?php the_permalink(); ?>">View Details</a>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
</div>
<?php $myvariable = ob_get_clean();
return $myvariable;
}
}