【发布时间】:2016-08-23 19:50:21
【问题描述】:
我为网站上的“俱乐部”部分创建了自定义帖子类型,我需要使用简码按类别过滤这些俱乐部。
不完全确定为什么短代码不能按类别过滤俱乐部(它确实显示了所有俱乐部)。
例如,如果其中一个类别是 AV 俱乐部,我尝试同时使用标题 [club category="AV Clubs"] 和 slug [club category="av-clubs"]。
// Shortcode
function shortcode_club_viusu( $atts ) {
//default arguments
$args = shortcode_atts( array(
'cat' => null,
'category' => '',
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page'=> -1,
'post_type' => 'club'
), $atts );
$content = "";
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
//beginning of the FAQ element
$content .= '<ul class="collapsible" data-collapsible="accordion">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$content .= '<li>';
$content .= '<div class="collapsible-header">'.get_the_title().'</div>';
$content .= '<div class="collapsible-body"><p>'.get_the_content().'</p></div>';
$content .= '</li>';
}
//closing the FAQ element
$content .= '</ul>';
} else {
$content .= "No Clubs found";
}
/* Restore original Post Data */
wp_reset_postdata();
return $content;
}
add_shortcode( 'club', 'shortcode_club_viusu' );
【问题讨论】:
标签: php wordpress custom-post-type shortcode