【发布时间】:2017-03-24 14:41:58
【问题描述】:
我使用代码从数据库中检索值。问题是它显示了所有值。我只需要显示两个值及其名称。名称为 External 和 Visual 的值
<?php $attributes = Custom_Post_Types::get_attributes(); ?>
<?php if ( ! empty( $attributes ) && is_array( $attributes ) && count( $attributes ) > 0 ) : ?>
<?php foreach( $attributes as $key => $attribute ) : ?>
<dt><?php echo wp_kses( $attribute['name'], wp_kses_allowed_html( 'post' ) ); ?></dt>
<dd><?php echo wp_kses( $attribute['value'], wp_kses_allowed_html( 'post' ) ); ?></dd>
<?php endforeach; ?>
<?php endif; ?>
【问题讨论】:
-
array_filter()。或者只在数据库中查询您实际需要的数据,而不是全部获取并在 PHP 中过滤
标签: php arrays wordpress attributes