1
我为网站上的“俱乐部”部分创建了自定义帖子类型,我需要使用简码过滤这些俱乐部的类别。按类别过滤自定义帖子类型短代码输出WordPress
不完全确定为什么短代码不能按类别过滤俱乐部(它显示所有俱乐部)。例如,如果其中一个类别是AV Clubs,我尝试使用标题[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');