Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将两个不同的查询合并为一个,并对查询进行分页-wordpress_Php_Wordpress_Pagination - Fatal编程技术网

Php 将两个不同的查询合并为一个,并对查询进行分页-wordpress

Php 将两个不同的查询合并为一个,并对查询进行分页-wordpress,php,wordpress,pagination,Php,Wordpress,Pagination,基本上,我想先显示带有“特色”标签的项目,然后显示所有没有“特色”标签的项目,然后对结果进行分页 $featured = array( 'post_type' => 'aircraft-refueling', 'tag' => 'featured' ); $not_featured = array( 'post_type' => 'aircraft-refueling', 'tag__not_in' => array('592') ); 以下是页码: function

基本上,我想先显示带有“特色”标签的项目,然后显示所有没有“特色”标签的项目,然后对结果进行分页

$featured = array(
'post_type' => 'aircraft-refueling',
'tag' => 'featured'
);
$not_featured = array(
'post_type' => 'aircraft-refueling',
'tag__not_in' => array('592')
);
以下是页码:

function pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
    'base' => str_replace($big, '%#%', get_pagenum_link($big)),
    'format' => '?paged=%#%',
    'current' => max(1, get_query_var('paged')),
    'total' => $wp_query->max_num_pages
));
}
我对PHP不太熟悉,但我猜我需要将查询合并到一个新查询中,然后对新查询进行分页?非常感谢您的帮助!如果有更好的方法,也请提供建议

编辑:这是我的进展。我几乎让它工作,但我得到了这个代码的错误,即使它看起来很好,我

<?php 
$featured = get_posts(array(
    'post_type' => 'aircraft-refueling',
    'tag' => 'featured'
    ));
$notfeatured = get_posts(array(
    'post_type' => 'aircraft-refueling',
    'tag__not_in' => array('592')
    ));
$mergedposts = array_merge( $featured, $notfeatured );

$postids = array();
foreach( $mergedposts as $item ) {
$postids[]=$item->ID;
}
$uniqueposts = array_unique($postids);

$posts = get_posts(array(
    'post__in' => $uniqueposts,
    'post_type' => 'aircraft-refueling',
    'post_status' => 'publish'
    ));
foreach( $posts as $post ) :
setup_postdata($post);
?>

然后,标准查询:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// THE CONTENT
<?php endwhile; ?>
<?php endif; ?>

//内容

根据上面提供的代码,我无法理解如何运行显示数据的循环。 如果您这样做了:


那么就不需要第二个循环:

while(have_posts()):the_post();?>
//内容
因为
setup\u postdata()
the\u post()
的作用基本相同-它们使用循环中的数据设置全局
$post
对象,所以像
the\u title()
the\u ID()
这样的模板标记可以正常工作

因此,你必须:

  • 如果使用
    query\u posts()