仅从数组中获取部分值



我使用代码从数据库中检索值。问题是它显示了所有值。我只需要显示两个值及其名称。名称为"外部"和"视觉"的值

<?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; ?>

然后添加对这两个值的检查。 请参阅下面的示例代码:

<?php foreach( $attributes as $key => $attribute ) : ?>  
        <?php if ($attribute['name'] == 'External'  || $attribute['name'] == 'Visual'){
            <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 } ?> 

最新更新