Sunday, October 16, 2022
HomeWordPress Developmentwp question - WordPress extraordinarily gradual when utilizing get_posts with a number...

wp question – WordPress extraordinarily gradual when utilizing get_posts with a number of meta_query relations


I’m having a problem with this question. Do I’ve it written incorrectly?
That is on WP 6.0.2 and PHP 7.4.30.

$now = current_time( 'Y-m-d H:i:s' );

// Fetch all upcoming bookings and occasions.
$posts = get_posts(
    array(
        'posts_per_page' => -1,
        'orderby'        => 'meta_value',
        'order'          => 'ASC',
        'fields'         => 'ids',
        'post_type'      => array( 'wc_booking', 'tribe_events' ),
        'post_status'    => array( 'paid', 'publish' ),
        'meta_query'     => array( //phpcs:ignore
            'relation' => 'OR',
            array(
                'relation' => 'AND',
                array(
                    'key'     => '_EventEndDate',
                    'worth'   => $now,
                    'sort'    => 'DATETIME',
                    'evaluate' => '>=',
                ),
                array(
                    'key'     => 'mse_tec_notification',
                    'worth'   => array( 'canceled' ),
                    'evaluate' => 'NOT IN',
                ),
            ),
            array(
                'relation' => 'AND',
                array(
                    'key'     => '_booking_end',
                    'worth'   => $now,
                    'sort'    => 'DATETIME',
                    'evaluate' => '>=',
                ),
                array(
                    'key'     => '_wc_booking_for_tribe_event',
                    'evaluate' => 'NOT EXISTS',
                ),
            ),
        ),
    )
);

After I run this question, WordPress will timeout ready for a consequence. It ought to return about 50 posts. On one other web site (with no upcoming occasions or bookings) the question takes 30 seconds to return 0 posts.

I’ve tried disabling all plugins and altering the theme nevertheless it didn’t assist.

If I take away one half of the “OR” meta_query at a time, every question takes 0.1 second. So it defintiely looks like a a number of relation meta_query drawback.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments