好,因此我需要在自定义category.php文件的帖子循环内显示ACF自定义字段。这是循环:
select o.orders_id, o.customers_email_address,
o.transaction_id,
o.customers_name, o.payment_method,
o.date_purchased, o.last_modified,
o.currency, o.currency_value, s.orders_status_name,
ot.text as order_total,
o.total_ord
from (select o.*,
count(*) over (partition by o. customers_email_address) as total_ord
from table_orders o
) o join
table_orders_total ot
on o.orders_id = ot.orders_id join
table_orders_status s
on o.orders_status = s.orders_status_id
where ot.class = 'ot_total'
order by o.orders_id desc
您可以看到循环显示类别(标题)中的页面,但我还需要显示简短说明。我知道我可以使用:
<div class="container">
<div class="row">
<?php
if ( have_posts() ) : ?>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
?>
<div class="col-xs-12 col-sm-4">
<?php the_title( '<h2><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
<div><?php MY_ACF_FIELD_GOES_HERE ?></div>
</div>
<?php
/* End the Loop */
endwhile;
?>
</div><!-- .row -->
</div><!-- .container -->
但是在这种情况下不是,因为摘录包含不需要在循环内的文本。因此,我需要为每个页面创建自己的简短描述字段。如何在category.php模板中显示它?自定义字段(我自己的简短说明)在所有页面上。
答案 0 :(得分:5)
您可以使用get_field('field_name')检索ACF字段值。例子-
<?php
$args = array( 'post_type' => 'speakers', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="entry-content">';
echo '<h2 class="speaker-name">';
the_title();
echo '</h2>';
echo '<img src="' . get_field('field_name') . '" alt="" />';
echo '<span class="speaker-title">';
the_field('title'); echo ' / '; the_field('company_name');
echo '</p>';
the_content();
echo '</div>';
endwhile;
?>