So I have a search function that just fetch custom posts and return them as a list.

function search() {

   // post query args
    $args = array(
        'post_type' => 'post_type',
        'posts_per_page' => -1,
        'post_status' => 'publish'

    // markup
    $markup = '<ul>';

    //the loop
    $loop = new WP_Query($args);
    while ($loop->have_posts()) {
        $markup .= '<li></li>';
    } wp_reset_postdata();

    $markup .='</ul>';

    echo $markup;

This works with under a hundred posts but with over a thousand posts, it doesn't. It just throws an error. If I switch to get_posts(), the same thing happens. Is there another way I could this?

  • Is the error a timeout error? – kaiser Oct 3 '12 at 2:07
  • @kaiser: That's another problem actually because our admin has not enabled error reporting in our server. Could you tell me if this should work and that the issue is on the server config or something? Because I can confirm that my function perfectly works on smaller number of posts. – jilseego Oct 3 '12 at 2:10
  • 1
    if it's not timing out, you're likely running out of memory – Milo Oct 3 '12 at 2:56
  • No error reporting? Stop working. Senseless task. – kaiser Oct 3 '12 at 10:20
  • @milo as an answer please – Rarst Oct 14 '12 at 21:00

If it's not timing out, you're likely running out of memory.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.