[英]posts_per_page displays only 2 posts instead of 4 posts
我有一个wordpress/php
代码,如下所示,我试图在下面的代码中在 A 行拉取最新的 4 个频道。
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
$instance_id
值为 49。使用 49 值时,它应该拉取4 latest channels
。
问题陈述:
我的代码在dev/staging server
运行良好(意味着它在 A 行拉取了最新的 4 个通道)但在生产服务器中它只拉取了 2 个通道。
我想知道我需要在上面的 php 代码中进行哪些更改,以便在生产服务器中提取最新的 4 个频道。
如果我在function get_latest_channels( $instance_id = false )
的 else 部分评论这一行'posts_per_page' => 4,
那么Line A
function get_latest_channels( $instance_id = false )
在开发服务器中提取30 posts
。
请检查 meta_key 的 wordpress WP_Query 语法。 如果 meta_value 是数字,则应使用“meta_value_num”而不是“meta_value”。
官方语法页面: https : //developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.