RM
Size: a a a
RM
MD
RM
М
RM
MD
MD
М
М
OV
MD
MD
MD
OV
MD
MD
PB
// Set up default query args.
$default_args = [
'post_status' => 'publish',
'post_type' => 'webinars',
'orderby' => 'title',
'order' => 'ASC',
];
// Set up custom query args.
$custom_args = [];
// Order entries.
if ( ! empty( $_POST['title'] ) ) {
$custom_args = [
'orderby' => 'title',
'order' => $_POST['title'],
];
}
if ( ! empty( $_POST['price'] ) ) {
$custom_args = [
'meta_key' => 'price',
'meta_type' => 'NUMERIC',
'orderby' => 'meta_value_num',
'order' => $_POST['price'],
];
}
if ( ! empty( $_POST['video_type'] ) ) {
$custom_args = [
'meta_key' => 'video_type',
'orderby' => 'meta_value',
'order' => $_POST['video_type'],
];
}
if ( ! empty( $_POST['date'] ) ) {
$custom_args = [
'meta_key' => 'date',
'meta_type' => 'DATETIME',
'orderby' => 'meta_value_datetime',
'order' => $_POST['date'],
];
}
if ( ! empty( $_POST['month'] ) ) {
$custom_args = [
'meta_key' => 'date',
'meta_type' => 'DATETIME',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => [
'relation' => 'OR',
],
];
foreach ( $_POST['month'] as $month ) {
$args['meta_query'][] = [
'key' => 'date',
'type' => 'DATETIME',
'value' => $month,
'compare' => 'LIKE',
];
}
}
// Additionally, filter entries.
if ( ! empty( $_POST['webinars_genre'] ) ) {
$custom_args['tax_query'] = [
[
'taxonomy' => 'webinars_genre',
'field' => 'id',
'terms' => $_POST['webinars_genre'],
],
];
}
if ( ! empty( $_POST['webinars_artist'] ) ) {
$custom_args['tax_query'] = [
[
'taxonomy' => 'webinars_artist',
'field' => 'id',
'terms' => $_POST['webinars_artist'],
],
];
}
// Merge any custom query args with defaults.
$args = wp_parse_args( $custom_args, $default_args );
// Execute the query.
$webinars = new WP_Query( $args );