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



这让我抓狂。我来解释一下情况。我有一个名为";afettiestivi";使用ACF,我创建了一个中继器,其中有一个组,该组由2个日期选择器字段组成,让客户标记房屋出租的时间段(例如,从2021/04/10到2021/04/20(所有日期都以"Y-m-d"格式存储,以便于查询数据库(中继器名称是";prenotazioni";组名称是";prenotazione";这两个日期选择器字段被称为"日期选择器"字段;伊尼西奥;以及";精细";

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

总结:
中继器名称:"Prenotazioni">
组名(中继器内部(:"Prenotazione">
日期选择器子字段1:"伊尼西奥
日期选择器子字段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()?>

EDIT由于我的进度为0,我试图看看问题出在哪里,如果查询本身或acf字段中,所以我完全删除了";中继器";字段,为了测试,我切换到了一个简单的";int";称为";测试";,这个查询现在正在工作并返回带有";测试";字段值>=4

'post_type' => 'affittiestivi',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND', // includes ACF stuff
array(
'key' => 'test',
'value' => '4',
'compare' => '>=',
),
)
);

所以现在我100%确定问题是(现在仍然是(";中继器字段";,我在税务查询上做错了什么"键";用于中继器内部的组子字段。我做错了什么?

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

$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',
),
));

最新更新