2017-03-24 3 views
1

코드를 사용하여 데이터베이스에서 값을 검색합니다. 문제는 모든 값을 표시한다는 것입니다. 나는 단지 두 개의 값과 그 이름이 필요하다. 이름이 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; ?> 
+1

array_filter을(). 데이터베이스를 쿼리하여 PHP에서 모두 필터링하고 필터링하면 실제로 필요한 데이터 만 쿼리합니다. – GordonM

답변

1

그런 다음 두 값에 대한 검사를 추가하십시오. 아래 예제 코드를 참조하십시오

<?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 } ?> 
+0

if와 함께 작동하지 않습니다. 나는 변수에 오류가 있다고 생각했다. 템플릿 작성자에게 연락하여 Inventor_Post_Types :: get_metabox_field_value() 함수를 사용하도록 제안했습니다. 나는 아직도 노력한다. 함수들입니다. –

+0

'public static function get_metabox_field_value ($ metabox_id, $ field_id, $ post_id = null, $ context = '개요') { \t \t $ field = cmb2_get_field ($ metabox_id, $ field_id); \t \t return self :: get_field_value ($ field-> args, $ post_id, $ context); \t} \t/** \t 공공 정적 기능 get_field_value ($ 필드, $ post_id를 = NULL, $ 컨텍스트 = '개요') { \t \t (빈 ($ post_id를)) { \t \t \t $ post_id를하는 경우 = get_the_ID(); \t \t \t \t $ value = get_post_meta ($ post_id, $ field [ 'id'], true); \t \t 경우 (! 빈 ($ 값) == 0 && strpos ($ 필드 [ '타입', 'taxonomy_')) { \t \t \t는 null; \t \t} –