Tell us what you are trying to do?
I try to order a view by two custom fields. It works fine so far. I just have a question regarding a small modification.
I use the code from the documentation (https://toolset.com/forums/topic/ordering-view-elements-by-two-custom-fields/)
add_filter( 'wpv_filter_query', 'sortieren_bewegunsplan_test',199,3 );
function sortieren_bewegunsplan_test( $query_args, $views_settings, $view_id) {
$view_ids = array( 43705 );
$args = array();
if (in_array($view_id, $view_ids)){
$args = array(
'meta_query' => array(
'relation' => 'AND',
'day-clause' => array(
'key' => 'wpcf-rask-von-tag',
'compare' => 'EXISTS',
'type' => 'NUMERIC'
),
'time-clause' => array(
'key' => 'wpcf-rask-von-uhrzeit-15-minuten',
'compare' => 'EXISTS',
'type' => 'NUMERIC'
)
),
'orderby' => array(
'day-clause' => 'ASC',
'time-clause' => 'ASC'
)
);
}
return array_merge($query_args, $args);
}
I need a little change in the day-clause. The wpcf-rask-von-tag should be a number greater than or equal TODAY() (see attached picture, where you can see the Query Filter of the View), instead of "compare with EXISTS"
Is there any documentation that you are following?
https://toolset.com/forums/topic/ordering-view-elements-by-two-custom-fields/
Is there a similar example that we can see?
no
What is the link to your site?
hidden link
Hello,
How do you setup the "wpcf-rask-von-tag" field? is it a custom date field created with Toolset Types plugin?
If it is, you can follow our document to setup the date field filter:
https://toolset.com/documentation/user-guides/views/date-filters/
And you don't need to setup custom PHP codes for "wpcf-rask-von-tag" field.
Hello Luo,
yes I did set up the date field filter according the following documentation: https://toolset.com/documentation/user-guides/views/date-filters/ (see attached picture of my first post).
However, the php overwrites the view's query filter for the "wpcf-rask-von-tag" field - and I need the php. Because without php, I can no longer order a view by two custom fields.
Yes, the "wpcf-rask-von-tag" is a custom date field created with Toolset Types plugin.
I found a solution:
add_filter( 'wpv_filter_query', 'sortieren_bewegunsplan',199,3 );
function sortieren_bewegunsplan( $query_args, $views_settings, $view_id) {
$view_ids = array( 43705 );
$args = array();
if (in_array($view_id, $view_ids)){
$today = current_time('timestamp');
$start_date = strtotime('0 day', $today);
$args = array(
'meta_query' => array(
'relation' => 'AND',
'day-clause' => array(
'key' => 'wpcf-rask-von-tag',
'value' => $start_date,
'compare' => '>=',
'type' => 'NUMERIC'
),
'time-clause' => array(
'key' => 'wpcf-rask-von-uhrzeit-15-minuten',
'compare' => 'EXISTS',
'type' => 'NUMERIC'
)
),
'orderby' => array(
'day-clause' => 'ASC',
'time-clause' => 'ASC'
)
);
}
return array_merge($query_args, $args);
}
My issue is resolved now. Thank you!