Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Query Loop Custom order having issues

  • Hi everyone,
    I have done this before, but for some reason this time it is not working.
    I have set this up only on SURF on the provided page – each section is in an accordion.
    The Grid has the Class entered (order_by_object_name).
    The PHP is:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
        // apply filter if loop has class: order_by_object_name
        if (! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order_by_object_name' ) !== false) {
            return array_merge( $query_args, array(
                'meta_key' => 'object_name',
                'orderby' => 'menu_item_order',
                'order' => 'ASC',
        return $query_args;
    }, 10, 2 );

    Originally the custom field menu_item_order was a number (via ACF), but I changed it to a text field, but no change.
    The PHP is entered in the child themes function.php
    ACF field (name a text field) is menu_item_order
    All that happens is that no menu items appear!
    I have tried a couple of different versions of this filter, but they all have the same result – probably missing something simple!
    TIA, Dave

  • Hi Dave,

    orderby be set to meta_value so your field’s value is taken into account. Reference:

    Have you tried that? Or, are you trying to achieve something else?

  • Thanks Fernando,
    I just had the meaning of the fields the wrong way around…
    All clear now and working 🙂

  • I see. You’re welcome!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.