Если кого-то интересует, как добиться результата для вопроса, который я написал, мне удалось его обработать!
Как правильные результаты мы показываем, но для каждой итерации foreach l oop вместо указанного c дня, мне удалось получить результаты для отображения / скрытия с помощью if (is_object_in_term ($ class-> ID, 'calendar-day', 'monday') && $ day-> term_id == 6). is_object_in_term проверяет, проверяются ли $ taxonomy по условиям объекта 'term_ids, names and slugs и $ day-> term_id для каждого из дней. Если это не так, то ничего не отображается.
Мне приходилось жестко кодировать каждый день недели и код для генерации результата. Я знаю, что это не лучший СУХОЙ подход, но сейчас я доволен текущей победой!
add_action('wp_ajax_classfilter', 'load_posts_by_ajax_callback');
add_action('wp_ajax_nopriv_classfilter', 'load_posts_by_ajax_callback');
function load_posts_by_ajax_callback() {
check_ajax_referer('load_more_posts', 'security');
$days = get_terms([
'taxonomy' => 'calendar-day'
]);
// Loop over days of the week
foreach ($days as $day ) {
$classesTable .= '<div class="response classes-col">';
$classesTable .= '<strong>' . $day->name . '</strong>'; // Day name
// Query arguments based on day of the week
$args = array(
'post_type' => 'calendar',
'meta_key' => 'classes_entry_start_time',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'numberposts' => '-1',
'tax_query' => array(
array(
'taxonomy' => 'calendar-day',
'field' => 'id',
'terms' => $day->term_id
// 'terms' => array('6', '7', '8', '9', '10', '11', '12')
)
),
);
if(isset( $_POST['theClass'])) {
$args['tax_query'] = array(
array(
'taxonomy' => 'calendar-class-type',
'field' => 'id',
'terms' => $_POST['theClass']
)
);
}
$query_classes = get_posts( $args );
$classesArray = array();
// Loop over query classes posts
foreach ($query_classes as $key => $class ) {
// Check if object has term: Monday
if (is_object_in_term($class->ID, 'calendar-day', 'monday') && $day->term_id == 6):
// $classesArray[] .= 'YES';
$start_time = get_field('classes_entry_start_time', $class);
$end_time = get_field('classes_entry_end_time', $class);
$classesEntry = get_field('classes_entry', $class);
// Create class item
$classesArray[] .= '<li>';
$classesArray[] .= '<a href="' . $classesEntry['booking_app_link'] . '" target="_blank" class="classes-item">';
$classesArray[] .= '<span>' . $classesEntry['start_time'] . '</span>';
$classesArray[] .= '<span>' . $class->post_title . '</span>';
$classesArray[] .= '<span>' . $classesEntry['duration'] . '</span>';
$terms = get_the_terms( $class->ID , 'calendar-class-type' );
if ($terms): foreach ( $terms as $term ):
$classesArray[] .= '<span>' . $term->name . '</span>';
endforeach; endif;
$classesArray[] .= '</a>';
$classesArray[] .= '</li>';
else:
// Show nothing
// $classesArray[] .= 'NO';
endif;
// Check if object has term: Tuesday
if (is_object_in_term($class->ID, 'calendar-day', 'tuesday') && $day->term_id == 7):
// $classesArray[] .= 'YES';
$start_time = get_field('classes_entry_start_time', $class);
$end_time = get_field('classes_entry_end_time', $class);
$classesEntry = get_field('classes_entry', $class);
// Create class item
$classesArray[] .= '<li>';
$classesArray[] .= '<a href="' . $classesEntry['booking_app_link'] . '" target="_blank" class="classes-item">';
$classesArray[] .= '<span>' . $classesEntry['start_time'] . '</span>';
$classesArray[] .= '<span>' . $class->post_title . '</span>';
$classesArray[] .= '<span>' . $classesEntry['duration'] . '</span>';
$terms = get_the_terms( $class->ID , 'calendar-class-type' );
if ($terms): foreach ( $terms as $term ):
$classesArray[] .= '<span>' . $term->name . '</span>';
endforeach; endif;
$classesArray[] .= '</a>';
$classesArray[] .= '</li>';
else :
// Show nothing
// $classesArray[] .= 'NO';
endif;
// Check if object has term: Wednesday
if (is_object_in_term($class->ID, 'calendar-day', 'wednesday') && $day->term_id == 8):
// $classesArray[] .= 'YES';
$start_time = get_field('classes_entry_start_time', $class);
$end_time = get_field('classes_entry_end_time', $class);
$classesEntry = get_field('classes_entry', $class);
// Create class item
$classesArray[] .= '<li>';
$classesArray[] .= '<a href="' . $classesEntry['booking_app_link'] . '" target="_blank" class="classes-item">';
$classesArray[] .= '<span>' . $classesEntry['start_time'] . '</span>';
$classesArray[] .= '<span>' . $class->post_title . '</span>';
$classesArray[] .= '<span>' . $classesEntry['duration'] . '</span>';
$terms = get_the_terms( $class->ID , 'calendar-class-type' );
if ($terms): foreach ( $terms as $term ):
$classesArray[] .= '<span>' . $term->name . '</span>';
endforeach; endif;
$classesArray[] .= '</a>';
$classesArray[] .= '</li>';
else :
// Show nothing
// $classesArray[] .= 'NO';
endif;
// Check if object has term: Thursday
if (is_object_in_term($class->ID, 'calendar-day', 'thursday') && $day->term_id == 9):
// $classesArray[] .= 'YES';
$start_time = get_field('classes_entry_start_time', $class);
$end_time = get_field('classes_entry_end_time', $class);
$classesEntry = get_field('classes_entry', $class);
// Create class item
$classesArray[] .= '<li>';
$classesArray[] .= '<a href="' . $classesEntry['booking_app_link'] . '" target="_blank" class="classes-item">';
$classesArray[] .= '<span>' . $classesEntry['start_time'] . '</span>';
$classesArray[] .= '<span>' . $class->post_title . '</span>';
$classesArray[] .= '<span>' . $classesEntry['duration'] . '</span>';
$terms = get_the_terms( $class->ID , 'calendar-class-type' );
if ($terms): foreach ( $terms as $term ):
$classesArray[] .= '<span>' . $term->name . '</span>';
endforeach; endif;
$classesArray[] .= '</a>';
$classesArray[] .= '</li>';
else :
// Show nothing
// $classesArray[] .= 'NO';
endif;
// Check if object has term: Friday
if (is_object_in_term($class->ID, 'calendar-day', 'friday') && $day->term_id == 10):
// $classesArray[] .= 'YES';
$start_time = get_field('classes_entry_start_time', $class);
$end_time = get_field('classes_entry_end_time', $class);
$classesEntry = get_field('classes_entry', $class);
// Create class item
$classesArray[] .= '<li>';
$classesArray[] .= '<a href="' . $classesEntry['booking_app_link'] . '" target="_blank" class="classes-item">';
$classesArray[] .= '<span>' . $classesEntry['start_time'] . '</span>';
$classesArray[] .= '<span>' . $class->post_title . '</span>';
$classesArray[] .= '<span>' . $classesEntry['duration'] . '</span>';
$terms = get_the_terms( $class->ID , 'calendar-class-type' );
if ($terms): foreach ( $terms as $term ):
$classesArray[] .= '<span>' . $term->name . '</span>';
endforeach; endif;
$classesArray[] .= '</a>';
$classesArray[] .= '</li>';
else :
// Show nothing
// $classesArray[] .= 'NO';
endif;
// Check if object has term: Saturday
if (is_object_in_term($class->ID, 'calendar-day', 'saturday') && $day->term_id == 11):
// $classesArray[] .= 'YES';
$start_time = get_field('classes_entry_start_time', $class);
$end_time = get_field('classes_entry_end_time', $class);
$classesEntry = get_field('classes_entry', $class);
// Create class item
$classesArray[] .= '<li>';
$classesArray[] .= '<a href="' . $classesEntry['booking_app_link'] . '" target="_blank" class="classes-item">';
$classesArray[] .= '<span>' . $classesEntry['start_time'] . '</span>';
$classesArray[] .= '<span>' . $class->post_title . '</span>';
$classesArray[] .= '<span>' . $classesEntry['duration'] . '</span>';
$terms = get_the_terms( $class->ID , 'calendar-class-type' );
if ($terms): foreach ( $terms as $term ):
$classesArray[] .= '<span>' . $term->name . '</span>';
endforeach; endif;
$classesArray[] .= '</a>';
$classesArray[] .= '</li>';
else :
// Show nothing
// $classesArray[] .= 'NO';
endif;
// Check if object has term: Sunday
if (is_object_in_term($class->ID, 'calendar-day', 'sunday') && $day->term_id == 12):
// $classesArray[] .= 'YES';
$start_time = get_field('classes_entry_start_time', $class);
$end_time = get_field('classes_entry_end_time', $class);
$classesEntry = get_field('classes_entry', $class);
// Create class item
$classesArray[] .= '<li>';
$classesArray[] .= '<a href="' . $classesEntry['booking_app_link'] . '" target="_blank" class="classes-item">';
$classesArray[] .= '<span>' . $classesEntry['start_time'] . '</span>';
$classesArray[] .= '<span>' . $class->post_title . '</span>';
$classesArray[] .= '<span>' . $classesEntry['duration'] . '</span>';
$terms = get_the_terms( $class->ID , 'calendar-class-type' );
if ($terms): foreach ( $terms as $term ):
$classesArray[] .= '<span>' . $term->name . '</span>';
endforeach; endif;
$classesArray[] .= '</a>';
$classesArray[] .= '</li>';
else :
// Show nothing
// $classesArray[] .= 'NO';
endif;
}
// Display all queried class results
$classesTable .= '<ul>' . implode(' ', $classesArray) . '</ul>';
$classesTable .= '</div>'; // END classes-col
}
echo $classesTable;
wp_die();
}