Hello,
I have a page built on Oxygen and I used Toolset to create some custom fields:
hidden link
I want the data to be sorted by 2 custom fields: NL Date (ASC) and Used As (ASC). The "Used As" field is stored as either 1 (for Primary) or 2 (AOTW) in the database. So the result I expect is that the data show up like this:
2022.07.01 Wed Primary
2022.07.01 Wed AOTW
2022.07.02 Thu Primary
2022.07.02 Thu AOTW
and so on...
I reached out to Oxygen support and they helped me to build the sorting part of the query:
<?php
function oxy_reorder_repeater($query) {
global $post;
if($query) {
$query->set('meta_query', array(
'relation' => 'AND',
'nl_clause' => array(
'key' => 'wpcf-last-used',
'compare' => '>=',
'value' => getBeginDate(),
'type' => 'numeric',
),
'nl_clause_2' => array(
'key' => 'wpcf-last-used',
'compare' => '<=',
'value' => getEndDate(),
'type' => 'numeric',
),
'used_clause' => array(
'key' => 'wpcf-used-as',
),
));
$query->set('orderby',array(
'nl_clause' => 'ASC',
'used_clause' => 'ASC',
));
}
}
add_action('pre_get_posts','oxy_reorder_repeater');
?>
As you can see, it works fine for July 2022. But if you select Aug 2022, you'll see that "2022.08.22 Mon Primary" is placed incorrectly. It's at the bottom of the list, instead of before "2022.08.22 Mon AOTW". It happens in the other months as well.
I have updated Oxygen with this finding and they have investigated further. But they were unable to find a solution. And since the custom fields are created with Toolset, they asked me to reach out to you to see if you can help with the correct wp_query. Can you please look into this and help me with a solution to fix the issue? Thank you.