【发布时间】:2026-01-29 12:40:02
【问题描述】:
有没有一种智能的方法可以通过 acf 单选按钮值对数组进行排序? 我有一个首页页面模板和几个带有自定义字段的子页面。
在首页我想显示来自子页面的一些值: 页面标题,以及子页面 acf 字段中的一些值 最后,我想按 acf 单选按钮值对数组进行排序。
单选按钮的值为:
one : A
two : B
three : C
four : D
five : E
该字段是强制性的,因此我不必测试是否有值。
<section id="info-box">
<?php
if(function_exists( 'get_field') ){
$query = new WP_Query( 'pagename=top-page' );
$services_id = $query->queried_object->ID;
wp_reset_postdata(); //* Restore original Post Data *//
$args = array(
'posts_per_page' => -1,
'post_type' => 'page',
'post_parent' => $services_id,
'orderby' => '', // radio button value //
'order' => 'ASC'
);
$services_query = new WP_Query( $args );
// The Loop
if ( $services_query->have_posts() ) {
echo '<ul class="info-box-list">';
while ( $services_query->have_posts() ) {
$services_query->the_post();
echo '<li class="list-item">';
echo '<div class="list-item-box">';
echo '<a href="' . get_permalink() . '" figure class="link-box-image">';
the_field('image');
echo '</figure>';
echo '</a>';
echo get_the_title();
the_field( 'sub-title' );
echo '</div>';
echo '</li>';
}
echo '</ul>';
}
/* Restore original Post Data */
wp_reset_postdata();
}
?>
</section>
现在我只是将字段转储到首页,直到我能确定是否有一种智能方法可以按单选按钮值对列表进行排序,acf 文档在单选按钮上并不是那么好功能。
【问题讨论】:
标签: javascript wordpress advanced-custom-fields