最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - posts_per_page displays only 2 posts instead of 4 posts

programmeradmin5浏览0评论

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

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

    return $rtn;
}

$instance_id = 49;
$latest_channels = HELLO\Channels\get_latest_channels($instance_id);
echo "<pre>"; print_r($latest_channels); echo "</pre>". // Line A

The value of $instance_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 at Line A) 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 in the production server.

If I comment this line 'posts_per_page' => 4, in the else section of the function get_latest_channels( $instance_id = false ) then Line A is pulling 30 posts in dev server.

发布评论

评论列表(0)

  1. 暂无评论