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 WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Query Loop Sort by Custom Field

  • Having an issue with the code from this page: https://docs.generateblocks.com/article/order-query-loop-by-custom-field/

    Here is what I have inside the Snippets Plugin:

    //CHAR type custom field value
    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
    
        // apply filter if loop has class: order-by-priority
        if (! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order-by-ambassador-state' ) !== false) {
           
            $query_args = array_merge( $query_args, array(
                'meta_key' => 'ambassador-state',
                'orderby' => 'meta_value',
                'order' => 'ASC',
            ));
        }
        return $query_args;
    }, 10, 2 );

    I have order-by-ambassador-state as the class for the grid inside the query loop.

    On the front end, the loop is broken and doesn’t display.

    Thanks,

  • Ok, I got it to work! Thank you

  • Great to hear that!

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