我为网站上的"Clubs"部分创建了一个自定义帖子类型,我需要使用短代码按类别过滤这些俱乐部。
不完全确定为什么短代码不能按类别过滤俱乐部(它确实显示所有俱乐部)。
例如,如果其中一个类别是AV俱乐部,我尝试使用标题[俱乐部类别="AV俱乐部"]和鼻涕虫[俱乐部类别="AV -俱乐部"]。
// 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' );
原来我在上面的列表中少了一行:
'cat' => null,
'club_tax' => '',
'category' => '',
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page'=> -1,
'post_type' => 'club'