最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - WordPress WP_Query make mysql time out

programmeradmin0浏览0评论

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

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)

  1. 暂无评论