Php 每页仅显示2篇文章,而不是4篇文章
我有一个Php 每页仅显示2篇文章,而不是4篇文章,php,wordpress,Php,Wordpress,我有一个wordpress/php代码,如下所示,我试图在下面代码的a行拉取最新的4个频道 function get_latest_channels( $instance_id = false ) { echo $instance_id; echo "<br>"; if ( ! $instance_id ) { $query_args = array( 'post_type' =&g
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\u id=false){
echo$instance\u id;
回声“”; 如果(!$instance\u id){ $query\u args=数组( “post_type”=>“你好频道”, “ep_integrate”=>正确, “每页帖子数”=>4, ); }否则{ $query\u args=数组( “post_type”=>“你好频道”, “ep_integrate”=>正确, 'meta_key'=>'instance_id', “元值”=>$instance\u id, “每页帖子数”=>4, ); } $channels=new\WP\u Query($Query\u args); 如果($channels->have_posts()){ $rtn=$channels->posts; } 返回$rtn; } $instance_id=49; $latest\u channels=HELLO\channels\get\u latest\u channels($instance\u id); 回声“;打印(最新频道);回声“/”A线
$instance\u id
的值是49。使用49值时,它应拉取4个最新频道
问题陈述:
我的代码运行良好dev/staging server
(意味着它在A行拉取最近的4个通道),但在生产服务器中,它只拉取2个通道
我想知道我需要在上面的php代码中做些什么更改,以便在生产服务器中获取最新的4个通道
如果我在函数get\u latest\u channels($instance\u id=false)的else部分注释这一行
'posts\u per\u page'=>4,
,那么行A
正在dev server中拉取30篇文章。请检查meta\u键的wordpress WP\u查询语法。如果meta_值是数字,则应使用“meta_值”而不是“meta_值”
官方语法页面:您有足够的数据吗?足够的数据吗?我不知道你的意思。你的hello频道有多少帖子?你需要一行一行地调试你的代码才能得到准确的错误。总共有30条,但我们只想发布前4条。我想知道是否有一个插件正在改变查询?就在$rtn=$channels->posts
之前,您可以检查$channels->query\u vars
包含哪些内容吗?另外,如果你删除每页的帖子,请将你得到的2个频道与30个频道进行比较,让我们知道这2个频道是在开头还是结尾。对不起,这是错误的:“如果meta_值是数字,你应该使用“meta_值”而不是“meta_值”。相反,正确使用meta\u value\u num
的示例是newwp\u查询('meta\u key=instance\u id&meta\u value=49&orderby=meta\u value\u num')
。如果meta值是数字,那么要使用的正确参数是meta\u type
,如newwp\u查询('meta\u key=instance\u id&meta\u value=49&meta\u type=numeric')
。