Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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 tax_查询和meta_查询的组合无法获取帖子_Php_Wordpress - Fatal编程技术网

Php tax_查询和meta_查询的组合无法获取帖子

Php tax_查询和meta_查询的组合无法获取帖子,php,wordpress,Php,Wordpress,我正在尝试使用meta_查询和tax_查询的组合来获取帖子,但是我无法使用两者的组合来获取帖子 下面是我的代码 <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'tm-property',

我正在尝试使用meta_查询和tax_查询的组合来获取帖子,但是我无法使用两者的组合来获取帖子

下面是我的代码

<?php 
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $args = array(
                        'post_type' => 'tm-property',
                        'posts_per_page'=>-1,
                        'meta_or_tax' => TRUE,                           
                        'paged' => $paged,
                        'order'             => 'DESC',

                        'tax_query' => array(
                                            array(
                                            'taxonomy' => 'tm-property_type',
                                            'field' => 'term_id',
                                            'terms' => $id
                                             )
                                    ),


                        'meta_query'       => array(
                        'relation'    => 'AND',                      
                                array(
                                    'key'          => '_tm_property_bedrooms',
                                    'value'        => $min_bed,
                                    'compare'      => '=',
                                ),

                                array(
                                    'key'          => '_tm_property_bathrooms',
                                    'value'        => $min_bath,
                                    'compare'      => '=',
                                ),                                                  
                    ),                                
            );

            $custom_posts = new WP_Query( $args );

            ?>

我得到一个空白数组

另外,我想要一个没有任何分类法的帖子列表

例如,我有5篇文章,2篇有分类法,其他3篇没有任何分类法

因此,当选择“分类名称”时,它将显示选定的分类帖子;当我没有选择“分类名称”时,它将显示“没有分类”的帖子


可以使用meta_查询和tax_查询的组合获取post吗?

请尝试以下参数进行查询

<?php
$category_object        = get_queried_object();
$category_taxonomy      = $category_object->taxonomy;
$category_term_id       = $category_object->term_id;

$min_bed = array( '1000', '4000' );
$min_bath = array( '2000', '3200' );

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'type'              => 'tm-property',
    'post_status'       => 'publish',
    'posts_per_page'    => 10,
    'paged'              => $paged, 
    'caller_get_posts'  => -1,
    'meta_query'        => array(
                                'relation' => 'AND',                      
                                array(
                                    'key'          => '_tm_property_bedrooms',
                                    'value'        => $min_bed,
                                    'type'    => 'numeric',
                                    'compare' => 'BETWEEN',
                                ),
                                array(
                                    'key'     => '_tm_property_bathrooms',
                                    'value'   => $min_bath,
                                    'type'    => 'numeric',
                                    'compare' => 'BETWEEN',
                                ),                                                  
                            ),      
    'tax_query'         => array(
                            array(
                            'taxonomy' => 'tm-property_type',
                            'field' => 'id',
                            'terms' => $category_term_id
                             )
                        ),   
    'orderby'           => 'name',               
    'order'             => 'DESC',                      
);
$custom_posts = null;
$custom_posts = new WP_Query($args);

if( $custom_posts->have_posts() ) :
    while ($custom_posts->have_posts()) : $custom_posts->the_post(); 
        echo get_the_title( $post->ID );
    endwhile;
endif;
wp_reset_query($custom_posts);
?>


这是可能的。查询生成的SQL是什么(
print$custom\u posts->request;
)?我在我的SQL中打印了$custom\u posts->request和pass query,但结果为空。这很奇怪。关于
var\u export($custom\u posts)
?仍然得到空白数组。什么是键“\u tm\u property\u beddrooms”和“\u tm\u property\u bathroms”)或“tm\u property\u beddrooms”和“tm\u property\u bathroms”?请检查。键是seme,“\u tm\u property\u bedrooms”的值在1000-4000之间,\u tm\u property\u bathrooms的值在2000-3200之间。获取帖子,但假设我没有选择任何分类法,则返回空数组。然后删除税务查询,并在参数中添加“taxonomy”=>“tm-property\u type”。放置arg if else条件,如if($category_term_id>0){带税查询}else{不带税查询。args}中只添加分类类型