在模板中尝试此代码。确保用相应的slug替换post\\u类型和自定义分类法(service&county)。
$page_link = get_permalink();
$services = get_terms( \'service\' );
$counties = get_terms( \'counties\' );
$args = array();
$args[\'post_type\'] = \'business\';
$args[\'paged\'] = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
if ( isset( $_GET[\'service\'] ) ) {
$args[\'service\'] = $_GET[\'service\'];
$page_link = add_query_arg( \'service\', $_GET[\'service\'], $page_link );
}
if ( isset( $_GET[\'county\'] ) ) {
$args[\'county\'] = $_GET[\'county\'];
$page_link = add_query_arg( \'county\', $_GET[\'county\'], $page_link );
}
if ( is_array( $services ) ) {
echo \'<ul>\';
foreach ( $services as $service ) {
echo \'<li><a href="\' . htmlentities( add_query_arg( \'service\', $service->slug, $page_link ) ) . \'">\' . $service->name . \'</a></li>\';
}
echo \'<li><a href="\' . htmlentities( remove_query_arg( \'service\', $page_link ) ) . \'">None</a></li>\';
echo \'</ul>\';
}
if ( is_array( $counties ) ) {
echo \'<ul>\';
foreach ( $counties as $county ){
echo \'<li><a href="\' . htmlentities( add_query_arg( \'county\', $county->slug, $page_link ) ) . \'">\' . $county->name . \'</a></li>\';
}
echo \'<li><a href="\' . htmlentities( remove_query_arg( \'county\', $page_link ) ) . \'">None</a></li>\';
echo \'</ul>\';
}
query_posts( $args );
if ( have_posts() ){
while ( have_posts() ) {
the_post();
// Do Something
// Pagination
}
}