WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
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
up vote 1 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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