(те, которые не являются локациями, являются танцевальными стилями и наоборот)
Код: Выделить всё
$locations = get_terms("categorycourses", array('include' => array(townLocation1, townLocation2)));
$dance_styles = get_terms("categorycourses", array('exclude' => array(townLocation1, townLocation2)));
$content = '';
foreach ( $locations as $location ) {
$content .= . ''.$location->name.'';
foreach ( $dance_styles as $dance_style ) {
//Show courses that is associated with this dance-style
//and in this location
$loop = get_loop_courses($dance_style, $location->term_id);
if($loop->have_posts()) {
//show courses here (post with custom post type course)
}
} //end dance_styles
} //end locations
function get_loop_courses($categorycourse, $location_id) {
$terms_slug = strtolower($categorycourse->slug);
$terms_slug = str_replace(' ','', $terms_slug);
$args = array(
'posts_per_page' => -1, //Show ALL coures (no limit)
'post_type' => 'course',
'tax_query' => array(
array(
'taxonomy' => 'categorycourses',
'field' => 'slug',
'terms' => $terms_slug
),
),
);
$args['tax_query'][] = array(
'taxonomy' => 'categorycourses',
'field' => 'id',
'terms' => array($location_id)
);
}
$loop = new WP_Query($args);
return $loop;
}
Код: Выделить всё
$locations = get_terms("categorycourses", array('include' => array(townLocation1, townLocation2)));
$dance_styles = get_terms("categorycourses", array('exclude' => array(townLocation1, townLocation2)));
$loop_arr = array();
$content = '';
foreach ( $locations as $location ) {
$content .= . ''.$location->name.'';
foreach ( $dance_styles as $dance_style ) {
//Show courses that is associated with this dance-style
//and in this location
$loop_arr[] = get_loop_courses($dance_style, $location->term_id);
} //end dance_styles
} //end locations
$loop = new WP_Query($loop_arr); //this is giving me an array but with a lot of posts, and not the ones I intended
function get_loop_courses($categorycourse, $location_id) {
$terms_slug = strtolower($categorycourse->slug);
$terms_slug = str_replace(' ','', $terms_slug);
$args = array(
'posts_per_page' => -1, //Show ALL coures (no limit)
'post_type' => 'course',
'no_found_rows' => true, //no pagination!
'tax_query' => array(
array(
'taxonomy' => 'categorycourses',
'field' => 'slug',
'terms' => $terms_slug
),
),
);
$args['tax_query'][] = array(
'taxonomy' => 'categorycourses',
'field' => 'id',
'terms' => array($location_id)
);
}
return $args;
}
Можно ли в этом случае использовать переходный процесс?
Подробнее здесь: https://stackoverflow.com/questions/253 ... in-wordpre
Мобильная версия