posts_per_page displays only 2 posts instead of 4 posts

Question

I have a wordpress/php code as shown below in which I am trying to pull latest 4 channels.

function get_latest_channels( $instance_id = false ) {
    echo $program_id;
    echo "<br>";
    if ( ! $instance_id ) {
        echo "I am inside the if block of channels";
        $query_args = array(
                'post_type'      => 'hello-channels',
                'ep_integrate'   => true,
                'posts_per_page' => 4,
        );
    } else {
        echo "I am inside the else block of channels";
        $query_args = array(
                'post_type'      => 'hello-channels',
                'ep_integrate'   => true,
                'meta_key'       => 'program_id',
                'meta_value'     => $program_id,
                'posts_per_page' => 4,
        );
    }
    $channels = new WP_Query( $query_args );
    if ( $channels->have_posts() ) {
        $rtn = $channels->posts;
    }

    return $rtn;
}

$program_id = 49;
$latest_channels = HELLOChannelsget_latest_channels($program_id);
echo "<pre>"; print_r($latest_channels); echo "</pre>"

The value of $program_id is 49. On using 49 value, it should pull 4 latest channels.

Problem Statement:

My code is working fine dev/staging server (meaning its pulling latest 4 channels) but in production server its pulling only 2 channels.

I am wondering what changes I need to make in the php code above so that it pulls latest 4 channels.

0
user5447339 4 months 0 Answers 9 views 0

Leave an answer