我从博客(https://tessakriesel.com/learn/how-to-filter-custom-post-types-by-acf-date-field/)获得了这个功能,但它在页面顶部显示了输出和不在我放置简码的元素中。我看到很多它与echo
. 但我不知道如何将我的代码更改为正确的工作代码:
function evenementen() {
$today = current_time('Ymd');
$args = array(
'post_type' => 'evenementen',
'posts_per_page' => '4',
'meta_key' => 'datum_evenement',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_query' => array(
array(
'key' => 'datum_evenement',
'compare' => '>=',
'value' => $today,
),
),
);
$children = new WP_Query($args);
?>
<?php if ($children->have_posts()) : ?>
<?php while ($children->have_posts()) : $children->the_post(); $fields = (object) get_fields(); ?>
<div class="event row">
<div class="event-logo col-sm-4">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'large', array( 'class' => 'img-responsive' ) ); ?></a>
</div>
<div class="event-details col-sm-8">
<h3 class="underline"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<h5><?php the_field('datum_evenement'); ?></h5>
<p class="call-to-action"><a href="<?php the_permalink(); ?>">Read More</a></p>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
<?php
} add_shortcode('nm2d_evenementen', 'evenementen');