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.

4
  • I don't see where $program_id is defined in get_latest_channels(). And in the production server, do you actually have more than 2 "channels" with the metadata instance_id? Try echo $channels->found_posts;.
    – Sally CJ
    Oct 1, 2020 at 0:50
  • I have updated my question. On doing echo $channels->found_posts;, I am getting 1920 Let me know if you need more information. Oct 1, 2020 at 1:18
  • Again, the issue is only in production server. Dev/Staging server seems to work perfectly fine. Oct 1, 2020 at 1:24
  • Do they share the same setup - data (settings, content, etc.), plugins and active theme? Have you tried with return get_posts( $query_args ); - got same results?
    – Sally CJ
    Oct 1, 2020 at 1:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.