-
chaoscontrol
I am following the instructions here : https://docs.generateblocks.com/article/order-query-loop-by-custom-field/
But can’t seem to get ordering by an ACF field working.Here is my code:
add_filter( ‘generateblocks_query_loop_args’, function( $query_args, $attributes ) {
// apply filter if loop has class: my-class-name
if (
! empty( $attributes[‘className’] ) &&
strpos( $attributes[‘className’], ‘in-date-order’ ) !== false
) {
// merge meta_key my-custom-field into query
return array_merge( $query_args, array(
‘meta_key’ => ‘event_date’,
‘orderby’ => ‘meta_value’,
‘meta_type’ => ‘DATE’,
‘order’ => ‘ASC’,
) );
}return $query_args;
}, 10, 2 );
I am using an ACF datepicker field.
-
Hi there,
It should work, did you add the
in-date-order
class to the Grid block of the query loop?Do you have order/order by parameter added to the query loop? If so, make sure you remove it.
Let me know 🙂
-
chaoscontrol
Thanks! I figured it out, it was just that someone had enabled the ‘Post Types Order’ plugin and that was messing things up.
-
Great! Glad you figured it out 🙂
- You must be logged in to reply to this topic.