• Hey

    Today I used AI to create a CPT events. Setup a custom meta field for event date. Setup an after event date passed the event would move from events category to past events category. But the one thing remaining was to sort the event in the Query Loop block by event date and not publish date. Man that was difficult. I gave up for now and made this Gutenberg issue: https://github.com/WordPress/gutenberg/issues/72749

    The question comes up can I use the Query Loop block or something like it that is just as good to customize the styling with your plugin?

    It would be very helpful and the result could also be shared on my WP tutorial site easywebdesigntutorials.com

Viewing 1 replies (of 1 total)
  • Yes. You can control how the Query Loop block queries and sorts posts using the query_loop_block_query_vars filter.

    Add the following code to your site plugin, theme’s functions.php, or a snippets plugin:

    function query_loop_vars( $query, $block, $page ) {
    if ( 'event' === $query['post_type'] ) {
    $query['orderby'] = 'meta_value';
    $query['meta_key'] = '_event_end';
    $query['order'] = 'DESC';
    }

    return $query;
    }
    add_filter( 'query_loop_block_query_vars', 'query_loop_vars', 10, 3 );

    This example sorts event posts by a custom meta field (_event_end) instead of publish date. The same filter can be used to modify other query parameters as needed.

    Ref: https://developer.wordpress.org/reference/hooks/query_loop_block_query_vars/

    • This reply was modified 4 months, 4 weeks ago by P.E.A. Lutz.
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.