2013-05-06 4 views
2

"Staff"에 대한 사용자 정의 게시 유형이 있습니다. 해당 게시물 유형은 "위치"(의사, 간호사 등)의 분류 체계를 가지고 있습니다. 나는 사용자가 페이지에서 특정 택 소노 미의 직원 만 반환 할 수 있도록하는 단축 코드를 만들려고합니다.WordPress Shortcode 분류 체계 속성 추가

예 : 나는 몇 가지 자습서를 다음 시도했지만이 작업을 얻이 수없는 것

[staff position="doctors"] 

. 여기까지 제가 가지고있는 코드는 모든 직원을 돌려줍니다.

function get_staff($atts) { 
$loop = new WP_Query(
    array (
     'post_type' => 'staff', 
     'orderby' => 'title' 
    ) 
); 

if ($loop->have_posts()) { 
    $output = '<div class="staff">'; 

    while($loop->have_posts()){ 
     $loop->the_post(); 
     $meta = get_post_meta(get_the_id()); 

     $output .= ' 
      <div class="staff" style="float: left; display: block; border: 1px solid #CCC; margin: 10px; padding: 12px; background-color: #eee;"> 
       <a href="' . get_permalink() . '"> 
        ' . get_the_post_thumbnail($post->ID, 'thumbnail') . '<br /> 
       ' . get_the_title() . '</a><br /> 
       ' . get_the_excerpt() . ' 
      </div> 
     '; 
    } 
    $output .= "</div>"; 
} else { 
    $output = 'No Staff Added Yet.'; 
} 

return $output; 
}; 

add_shortcode('staff', 'get_staff'); 

도움을 주셔서 감사합니다.

답변

2

extract the attribute이 필요하고 검색어에 추가해야합니다.

extract(shortcode_atts(array('position' => 'doctors'), $atts)); // $position variable will be initialized to 'doctors' if the shortcode is missing the 'position' parameter 

$loop = new WP_Query(
    array (
     'post_type' => 'staff', 
     'orderby' => 'title', 
     'position' => $position 
    ) 
); 
+0

감사합니다. 나중에 사용하도록 북마크 됨. –