Crocoblock / suggestions

The suggestions for CrocoBlock project
194 stars 78 forks source link

JetEngine: Repeater Listing Grid sortable #2070

Open petranca opened 3 years ago

petranca commented 3 years ago

When I insert the Repeater Listing into the Listing Grid, I cannot sort it. It always takes the order of the repeater entries. But it would also be good if I could sort by a metafield like I do with posts or taxonomies.

anderoav commented 3 years ago

+1

tadytomas commented 1 year ago

+1

stijnvanouplines commented 5 months ago

There is a hook in JetEngine you can use: jet-engine/query-builder/query/items

For example, sort a repeater query by the 'floor' field

add_filter( 'jet-engine/query-builder/query/items', function ( $items, $query ) {
    if ( $query->id !== 2 ) { // Change this number with the ID of your query
      return $items;
    }

    usort( $items, function( $a, $b ) {
        return $a->floor - $b->floor;
    } );

    return $items;
}, 10, 3 );

Put this code in the functions.php file of your current theme