Posts per page

Discussion in 'PHP' started by SharingEngines, Jan 15, 2012.

  1. #1
    Hi,

    I have this wordpress code, but i have a problem with "posts_per_page" function. He dosen't limit the 2 posts per page.
    Can you help me please?
    Thank you for your help

    <?php
    $display_count = ( get_option( 'cp_sys_top_ad_count' ) ) ? intval( get_option( 'cp_sys_top_ad_count' ) ) : 2;
    $term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') );
    
    $args = array(
        'post_type' => 'ad_listing',
        'post_status' => 'publish',
        'orderby' => 'rand',
        'ad_cat' => $term->slug,
        'meta_key' => 'cp_sys_top_price',
        'posts_per_page' => $display_count,
        'nopaging' => true
    );
    
    $top_query = new WP_Query($args);
    ?>
    
        <?php if ($top_query->have_posts()) : ?>
    
    
            <?php 
            while( $top_query->have_posts() ) : $top_query->the_post();
            
            $highlight = get_post_meta( $post->ID, 'cp_sys_highlight_price', true );
            $high_class = ( $highlight ) ? ' highlight_ad' : '';
            ?>
    Code (markup):
     
    SharingEngines, Jan 15, 2012 IP
  2. waynewex

    waynewex Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried echoing the variable $display_count to make sure that you're actually getting a value?
     
    waynewex, Jan 15, 2012 IP