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()) {
$loop->the_post();
$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?
If it’s not timing out, you’re likely running out of memory.