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 ACF查询排除中继器内2个日期选择器组之间的日期_Php_Wordpress_Datepicker_Advanced Custom Fields - Fatal编程技术网

Php ACF查询排除中继器内2个日期选择器组之间的日期

Php ACF查询排除中继器内2个日期选择器组之间的日期,php,wordpress,datepicker,advanced-custom-fields,Php,Wordpress,Datepicker,Advanced Custom Fields,这让我快发疯了。我来解释一下情况。 我有一个叫“affittiestivi”的自定义帖子 使用ACF i创建了一个包含一个组的中继器,该组由2个日期选择器字段组成,以便客户标记房屋租赁的时间段(例如,从2021/04/10到2021/04/20(所有日期都以“Y-m-d”格式存储,以便更容易地查询DB) 中继器名称为“prenotazioni”组名称为“prenotazione”两个日期选择器字段分别称为“Inziio”和“fine” 用户可以搜索入住和退房日期(2个简单的html日期输入) 然

这让我快发疯了。我来解释一下情况。 我有一个叫“affittiestivi”的自定义帖子 使用ACF i创建了一个包含一个组的中继器,该组由2个日期选择器字段组成,以便客户标记房屋租赁的时间段(例如,从2021/04/10到2021/04/20(所有日期都以“Y-m-d”格式存储,以便更容易地查询DB) 中继器名称为“prenotazioni”组名称为“prenotazione”两个日期选择器字段分别称为“Inziio”和“fine”

用户可以搜索入住和退房日期(2个简单的html日期输入) 然后,我需要查询这段时间内可用的所有帖子,如果一个房子是从2021/04/10到2021/04/20预订的,我搜索2021/04/11和2021/04/19,它不应该显示。如果我搜索2021/04/21和2021/04/30之间的帖子应该显示。 我正在尝试元查询,但无论如何,帖子都不会显示

总结:
repear name:“Prenotazioni”
组名(内部中继器):“Prenotazione”
日期选择器子字段1:“Niziio”
日期选择器子字段2:“良好”

任何帮助都将不胜感激,对我的英语感到抱歉
到目前为止我所拥有的

/* Template Name: Ricerca Affitti */
<?php get_header();
 
$stype = $_GET['type'];
$searched_arr = $_GET['startdate'];
$searched_leave = $_GET['endate'];
 
$args = array(
     'post_type' => 'affittiestivi',
          'posts_per_page' => -1,
    );
$immobili = new WP_Query( $args ); //This query i't just to acces subfields value,
 //i know it's not the best practice tho and i'm not even sure i need this at this point
?>
 
<?php if($immobili->have_posts()) : while ($immobili->have_posts()) : $immobili->the_post(); ?>
<?php if( have_rows('prenotazioni') ): ?>
<?php while( have_rows('prenotazioni') ): the_row(); 
$data = get_sub_field('prenotazione');
$booked_from = $data['inizio'];
$booked_to = $data['fine'];
//This is working fine, var_dumped everything and they return yy-mm-dd, same format as the user input
 
$s_args = array(
    'post_type' => 'affittiestivi',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'order' => 'DESC',
    'meta_query' => array(
       'relation' => 'AND',
            array(
                'key' => 'prenotazione_inizio', //Is this the right way??
                'compare' => '>=',
                'value' => $searched_arr
            ),
             array(
                'key' => 'prenotazione_fine',
                'compare' => '<=',
                'value' => $searched_leave
            ),
    
          )
    );
endwhile;
endif;
//end acf row loop
endwhile;
endif;
//end custom Loop
$result = new WP_Query( $s_args );
if($result->have_posts()) : while ($result->have_posts()) : $result->the_post(); ?>

 //This query is always empty

<h1><?php the_title();?></h1>
 
<?php endwhile;
endif;
wp_reset_postdata();
get_footer()?>
因此,现在我100%确定问题是(现在仍然是)中继器字段,我在中继器内的组子字段的税务查询“key”上做错了。
我做错了什么?

请检查下面的代码。您可以使用下面的查询查询日期范围

$args = array(  
'post_type' => 'events',
'posts_per_page' => -1,
'meta_key' => 'start_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
    'relation' => 'AND',
    array(
        'key' => 'start_date',
        'value' => $today,
        'compare' => '<=',
        'type' => 'NUMERIC',
    ),
    array(
        'key' => 'end_date',
        'value' => $today,
        'compare' => '>=',
        'type' => 'NUMERIC',
    ),

));
$args=数组(
“post_类型”=>“事件”,
“每页帖子数”=>-1,
“元密钥”=>“开始日期”,
'orderby'=>'meta_value_num',
“订单”=>“ASC”,
“元查询”=>数组(
'关系'=>'和',
排列(
'键'=>'开始日期',
“价值”=>今天的美元,
“比较”=>“=”,
'类型'=>'数值',
),
));
$args = array(  
'post_type' => 'events',
'posts_per_page' => -1,
'meta_key' => 'start_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
    'relation' => 'AND',
    array(
        'key' => 'start_date',
        'value' => $today,
        'compare' => '<=',
        'type' => 'NUMERIC',
    ),
    array(
        'key' => 'end_date',
        'value' => $today,
        'compare' => '>=',
        'type' => 'NUMERIC',
    ),

));