php ACF块自定义字段查询

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php ACF块自定义字段查询相关的知识,希望对你有一定的参考价值。

<?php
$events = new WP_Query( array( 
    'post_type' => 'events', 
    'orderby' => 'date', 
    'order' => 'ASC',
));
?>

<div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">
		<h2>Events</h2>
		<?php if ( $events->have_posts() ):
            while ( $events->have_posts() ) : $events->the_post(); ?>
                <div class="event">
                    <h5><?php the_title(); ?></h5>
                    <strong><?php echo get_field( 'event_date', get_the_ID() ); ?></strong>
                    <div><?php echo get_field( 'event_location', get_the_ID() ); ?></div>
                    <?php if( get_field( 'event_details', get_the_ID() ) == 'website' ): ?>
                        <a href="<?php echo get_field( 'event_website_link', get_the_ID() ); ?>" target="_blank">Event Details</a>
                    <?php endif; ?>
                    <?php if( get_field( 'event_details', get_the_ID() ) == 'pdf' ): ?>
                        <a href="<?php echo get_field( 'event_pdf', get_the_ID() ); ?>" target="_blank">Event Details</a>
                    <?php endif; ?>
                </div>
			<?php endwhile; ?>
		<?php wp_reset_postdata();
		endif; // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
		<p><a href="https://www.mypcnow.org/resources/submit-an-event/" class="btn btn-primary">Submit an event</a></p>
</div>

以上是关于php ACF块自定义字段查询的主要内容,如果未能解决你的问题,请参考以下文章

php 通过acf选择字段查询类别中的自定义帖子类型

php ACF自定义CSS字段

php 搜索自定义字段:在Wordpress搜索中包括自定义字段/ ACF

php 将自定义字段添加到ACF对象选择

php ACF自定义字段作为WordPress帖子标题

按关系字段 (ACF) 的 Elementor 帖子的自定义查询过滤器