• Hello,
    I had a sidebar widget working on my website. I use a php code plugin to use php on the sidebar. Anyway, I used the following code to list all the posts on my website in a dropdown menu. However, ever since the number of posts reached 750, the query will return an error:

    “Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0”

    When I lower the number of posts to show, the code will work. So is 750 a wordpress limit to help lower the site load? Is there a way to increase that? Thanks very much in advance.

    The code:

    <form action="<? bloginfo('url'); ?>" method="get">
     <select style="border-width:15pxborder-color:#c6c6c6; width: 77mm; background-color: #fff; font-family:Open Sans; font-size: 9pt;" onchange='this.form.submit()' name="page_id" id="page_id">
     <OPTION SELECTED value=""><b>--Tüm Destinasyonlar (Alfabetik)--</b>
     <?php
     global $post;
     $args = array( 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' );
     $posts = get_posts($args);
     foreach( $posts as $post ) : setup_postdata($post); ?>
                    <option value="<? echo $post->ID; ?>"><?php the_title(); ?></option>
     <?php endforeach; ?>
     </select>
    
     </form>
    <br>
    <center>
    <span style="font-size: 12px;">?u anda sitede <b><?php
    $published_posts = wp_count_posts();
    echo $published_posts->publish;
    ?></b> destinasyon yer almaktad?r.</span></center>
Viewing 1 replies (of 1 total)
  • Here’s problem 1.) You’re trying to put 750+ post titles in a dropdown, and problem 2.) You’re pulling ALL post data from 750+ posts.

    In problem 1 you’re going to eventually crash the browser when you get more than 1-2,000+ entries, I’ve seen it happen.

    To solve problem two, you use the fields => 'ids' parameter, and return ONLY ids. This would of course require you to modify your loop, but would overall help with the amount of data stored in PHP’s memory at the time of execution.

    Overall Solution
    Switch to a sort of ‘auto-suggest’ or auto-complete search field instead. I’m sure they’re out there, putting that many things in a dropdown is just crazy!

Viewing 1 replies (of 1 total)
  • The topic ‘Query more than 750 posts’ is closed to new replies.