• Hi, I tried below code from Order Query Loop By Custom Field

    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-priority’ ) !== false ) {
    // Add tag filter
    $query_args = array_merge( $query_args, array(
    ‘meta_key’ => ‘priority’,
    ‘orderby’ => ‘meta_value_num’,
    ‘order’ => ‘ASC’,
    ));
    }
    return $query_args;
    }, 10, 2 );

    It works well but when I set query parameters to specific taxonomy in ‘Query Loop’ block, It shows nothing.

    I’d like to show posts from specific tag, and I want posts to be shown with ‘priority’ meta key’s number order.

    Any advice would be appreciate. Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    what Taxonomy parameter did you set in the Query Loop ? Did it include a specific term ?

    Thread Starter mixingmag

    (@mixingmag)

    I’d like to add taxonomy parameter of tag ‘article’.

    It works with only using Query Loop’s taxonomy. but when I set a php filter I mentioned above to grid’s additional CSS, it failed.

    If not using Query Loops’s taxonomy, php filter works well that show every post in my website ordered by ‘priority’ meta key’s number value.

    Hi @mixingmag,

    array_merge in the code should prevent that from occurring.

    How are you adding that PHP? Do you have any other PHP added that filters a Query Loop?

    To test, can you try adding a different parameter and see if that would be affected as well?

    Thread Starter mixingmag

    (@mixingmag)

    I tried again in different page and now I can see it works very well.

    Now I confirmed that there is no problem with the above code regarding the setting of Query Loop’s taxonomy.

    Maybe there was a conflict with another PHP code I set.

    Thank you for your support. I appreciate it.

    I see. Glad you got it working!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Order Query Loop By Custom Field with taxonomy’ is closed to new replies.