dongshan4518 2014-01-28 15:37
浏览 173
已采纳

在'posts_per_page'=> -1时失败

The context: I have created a store search for a website that has listed in it's database around 1300 stores. The user enters in their postcode and is returned to them the 10 closest stores to that postcode the stores that sell the product being advertised.

The following code (php) is what I have been using for the initial search, it is looking for data in the custom taxonomy and creating an array in order to later use that data to further work out distances.

     // If lat & lng supplied, find the 10 nearest stores

    if( isset( $_GET['lat'] ) && isset( $_GET['lng'] ) ){

        $latlng = true;
        global $wp_query;

        // If the country has been set, add it to the query
        if( isset($_GET['country']) && $_GET['country'] == "true" ){

            if($_GET['ss'] == "UAE"){
                $countryname = "United Arab Emirates";
            } else {
                $countryname = $_GET['ss'];
            }

            $args = array_merge( $wp_query->query, array( 'posts_per_page' => -1, 
                                                         'meta_key' => 'latitude', 
                                                         'store-country' => $countryname ) );   

        } else {
            $args = array_merge( $wp_query->query, array( 'posts_per_page' => -1, 
                                                         'meta_key' => 'latitude' ) );  
        }





        //echo $wp_query->found_posts;

        query_posts($args);

The code above is directly below <?php get_header(); ?>

What is happening is the header of the page is loading and ONLY the header as the rest of the page has failed to load.

I have found the problem is occuring with this line here:

$args = array_merge( $wp_query->query, array( 'posts_per_page' => -1, 

If I set posts_per_page set to 400 or anything below the code begins working the information is brought back and the page continues just fine, I am just not able to bring back ALL entries which I require. If I had less than 400 entries then there wouldn't be an issue, however I need to be able to bring back 1300 entries and that number is for ever increasing as the product is being addded to more stores.

As I understand -1 should bring back all the entries without pagenation but something is failing and I am being forced to give a specific number for posts_per_page which seems just unreasonable considering the circumstances.

It has all been working fine on my localhost, it is just occuring when the site has been live, I am being led to think that it must be something with the server settings by my hosting provider, but I wouldn't know what they would be or if that is indeed the case.

  • 写回答

1条回答 默认 最新

  • dqys98341 2014-01-28 15:53
    关注

    If I set posts_per_page set to 400 or anything below the code begins working

    This suggests to me that it's a timing out issue. Your production server probably has certain limits that your local server did not, which is why you didn't see this problem. If you have access to php.ini you can try increasing max_execution_time or memory_limit, see if those help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False