• Hello, my Custom post has ~12000 posts with 20 meta fields in each post. When i try to query posts with -1 as post per page it gives me no result and even don’t execute the next lines of code. Any Help would be appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Have you checked for any errors?

    A good pointer in such situations is to turn WP_DEBUG to true in your wp-config.php. Usually it will tell you how it’s feeling if something is hurting.

    Thread Starter AeyzazKhan

    (@aeyzazkhan)

    i am using the following code to get the number of posts on the basis of their meta field.

    function getids() {
    $args = array(
    ‘post_type’ => ‘mycustompost’,
    ‘posts_per_page’ => -1
    );
    $ids = array();
    $posts = get_posts($args);
    foreach($posts as $post) {
    $pid = get_post_meta($post->ID,”lp_id”,true);
    if ( !empty( $pid ) ) {
    $ids[] = $pid;
    }
    }
    return $ids;
    }

    So, do you see posts or do you not see posts?

    In your original post your said you got no result, but now you see results?

    Anyways, you have no pagination in your code.

    The WP Query need the paged parameter du decide which page you are on. Even then you will get no new results (as -1 already lists all posts).

    From the WordPress Codex:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
      'posts_per_page' => 3,
      'paged' => $paged
    );
    
    query_posts($args);
    ?>

    You need to tell WordPress which page you are on, and how many you want per page (not infinity as there is no infinity*2)

    Thread Starter AeyzazKhan

    (@aeyzazkhan)

    Sorry if i was not clear, All i want is to get the number of posts from above code and use that in pagination.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Increasing Post per page Limit’ is closed to new replies.