我有一个由开发人员在我之前开发的网站,我很幸运,试图弄清楚如何解决他的问题。
我目前正在尝试展示今天的活动。这是一个CPT并具有自定义字段。我不确定我是否只是长时间看了这段代码而我只是错过了答案或者什么但我无法看到我出错的地方。
我不仅没有得到任何结果我得到“致命错误:在我的”日期:“部分中对非对象调用成员函数格式()。
我已经阅读并尝试了无数的可能性而没有成功。我希望一副新鲜的眼睛可以帮助我。
以下是代码:
<?php
$today = current_time('Ymd');
$args = array(
'post_type' => 'posts_events',
'post_status' => 'publish',
'posts_per_page' => 3,
'meta_query' => array(
array(
'key' => 'start_date',
'compare' => '>=',
'value' => $today,
)
),
'meta_key' => 'start_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ));
?>
<!-- CONTENT STARTS -->
<div class="wrapper">
<div class="container_16" id="event-list_container">
<div class="col_14 prefix_1">
<?php
$taxonomy = 'sbts';
$orderby = 'name';
$show_count = 1; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
//'show_count' => $show_count,
//'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
?>
<ul class="taxonomy-list-links">
<?php wp_list_categories( $args ); ?>
</ul>
</div>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="container_14 prefix_1 suffix_1 event-list">
<?php $background_image = MultiPostThumbnails::get_post_thumbnail_id(get_post_type(), 'event-thumb', $post->ID); $background_image = wp_get_attachment_image_src( $background_image,'event-thumb' ); ?>
<div class="col_5 event-photo" style="background-image:url(<?php echo $background_image[0]; ?>);"></div>
<div class="col_8 prefix_5 event-content">
<h2><?php the_title(); ?><?php if($today > get_field('end_date')) echo '</h2><p>Past Event</p>'; ?>
<?php $firm = get_field('host_firm'); ?>
<h3>Member Host Firm: <span class="event-p"><?php echo $firm[0]->post_title; ?></span></h3>
<h3>Location: <span class="event-p"><?php echo get_field('event_location'); ?></span></h3>
<h3>Dates: <span class="event-p"><?php $date = DateTime::createFromFormat('Ymd', get_field('start_date')); echo $date->format('M j, Y'); ?> - <?php $date = DateTime::createFromFormat('Ymd', get_field('end_date')); echo $date->format('M j, Y'); ?></span></h3>
<a href="<?php the_permalink(); ?>" class="button_gray">Event Details</a>
</div>
</div>
<?php endwhile; ?>
<div class="wrapper">
<div class="container_16 nested" id="page-navigation_container">
<div class="col_14 gap prefix_1" id="page-navigation"><?php theme_pagination(); ?></div>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- CONTENT STOPS -->
<?php get_footer(); ?>
答案 0 :(得分:-1)
您需要对要为循环传递的args使用新查询:
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();