WordPress WP_Query make mysql time out

Question

I got a problem that I install XAMPP on my computer to develop,and recently I want to use WordPress to expand two functions:
1.posts pinned and deadline is required (the post will not pinned when time is up)
2.posts remove from the list and deadline is requured too (the post will be removed from the post list when time is up)

so I use ACF plugin to create 4 meta_key:
1.news_down_date_bollen — whether set post remove date (Data type:Boolean)
2.news_down_date — post remove from the list deadline (Date type:date)
3.news_top — whether to pined the post(Data type:Boolean)
4.news_top_date — pined deadline (Date type:date)

this is UI screenshot

enter image description here

And then I use WP_Query to display post list on the page this is snippet in my WP_Query

'meta_query' => array(
'relation'  => 'AND',
array( // check remove post condition
    'relation'  => 'OR',
    array(
        'relation'  => 'AND',
        array(
            'key' => 'news_down_date_bollen',
            'value' => 1,
            'compare' => '='
        ),
        array(
            'key'       => 'news_down_date',
            'value'     => date('Ymd'),
            'compare'   => '>='
        ),
    ),
    array(
        'key' => 'news_down_date_bollen',
        'value' => 0,
        'compare' => '='
    )
),
array( // check pined condition
    'relation' => 'AND',
    array(
        'key'     => 'news_top',
        'value'   => 1,
        'compare' => '='
    ),
    array(
        'key'       => 'news_top_date',
        'value'     =>  date('Ymd'),
        'compare'   => '>='
    )
)

It works and display the pined post in the post list,but when I have too much pined posts.the page will crach and mysql will use my computer CPU to 100% !!

So I don’t know if there is a problem with my code or is there a good solution? My english is not so good.Thank you for your patience and reading.

0
cindy 2 years 2020-10-24T20:10:23-05:00 0 Answers 17 views 0

Leave an answer

Browse
Browse