我有一个Wordpress自定义搜索表单,用于搜索各种建筑的楼层。例如,当用户搜索1000到1500平方英尺之间的楼层时,他将获得所有在这些值之间具有自由楼层空间的建筑的列表。
搜索值存储在Cookie中,因为我需要它们出现在单体建筑页面上。
在“single building”页面上,有一个部分显示符合用户搜索条件的楼层。
它与我不久前添加的地板配合得很好。当我添加新楼层时,它们不会显示在单体建筑页面上
那会是什么?以下是我编写的代码,用于将匹配的楼层显示到单个建筑页面:
<table class="table" id="tab1C">
<?php include( get_template_directory().\'/inc/function-search.php\' );
$categories = get_the_category();
$category_id = $categories[0]->cat_name;
$args = array(
\'meta_query\' => array(
$sq_array,
$mt_array,
$prelet_array,
$date_array,
),
\'category_name\' => $category_id,
);
$i = 0;
$search = array_merge($args);
$propertySearch = new WP_Query( $search ); ?>
<?php $terms = get_the_terms( get_the_ID(), \'category\');
if( !empty($terms) ) : $term = array_pop($terms); ?>
<?php if( $propertySearch->have_posts() ) : while( $propertySearch->have_posts() ) : $propertySearch->the_post(); ?>
<?php get_template_part( \'content\', \'table\' ); ?>
<?php $i++; ?>
<?php endwhile; endif;
wp_reset_postdata(); ?>
<?php endif; ?>
</table>
这是函数搜索。php包括
<?php
$_minsq = $_GET[\'minsq\'] != \'\' ? $_GET[\'minsq\'] : \'\';
$_maxsq = $_GET[\'maxsq\'] != \'\' ? $_GET[\'maxsq\'] : \'\';
$_minmt = $_GET[\'minmt\'] != \'\' ? $_GET[\'minmt\'] : \'\';
$_maxmt = $_GET[\'maxmt\'] != \'\' ? $_GET[\'maxmt\'] : \'\';
$unit = $_GET[\'unit\'] != \'\' ? $_GET[\'unit\'] : \'\';
$prelet = $_GET[\'prelet\'] != \'\' ? $_GET[\'prelet\'] : \'\';
$date = $_GET[\'date\'] != \'\' ? $_GET[\'date\'] : \'\';
$sorter = $_GET[\'sorter\'] != \'\' ? $_GET[\'sorter\'] : \'\';
$sq_array = array();
$mt_array = array();
$prelet_array = array();
$date_array = array();
$sorter_array = array();
if ( isset( $_COOKIE["unit"] )){
if ($_COOKIE["unit"] == "ft") {
if ( isset( $_COOKIE["minsq"] )){
$value_min = intval( $_COOKIE["minsq"] );
//update_post_meta( $post->ID, \'wpcf-square-feet\', $value_min );
}
if ( isset( $_COOKIE["maxsq"] )){
$value_max = intval( $_COOKIE["maxsq"] );
//update_post_meta( $post->ID, \'wpcf-square-feet\', $value_max );
}
$sq_array = array(
array (
\'key\' => \'wpcf-square-feet\',
\'value\' => array( $value_min, $value_max ),
\'type\' => \'numeric\',
\'compare\' => \'BETWEEN\',
),
array(
\'key\' => \'wpcf-square-feet\',
\'value\' => $value_min,
\'type\' => \'numeric\',
\'compare\' => \'>=\',
),
array(
\'key\' => \'wpcf-square-feet\',
\'value\' => $value_max,
\'type\' => \'numeric\',
\'compare\' => \'<=\',
)
);
} elseif ($_COOKIE["unit"] == "mt") {
if ( isset( $_COOKIE["minmt"] )){
$value_minmt = intval( $_COOKIE["minmt"] );
//update_post_meta( $post->ID, \'wpcf-square-meters\', $value_minmt );
}
if ( isset( $_COOKIE["maxmt"] )){
$value_maxmt = intval( $_COOKIE["maxmt"] );
//update_post_meta( $post->ID, \'wpcf-square-meters\', $value_maxmt );
}
$mt_array = array(
array (
\'key\' => \'wpcf-square-meters\',
\'value\' => array( $value_minmt, $value_maxmt ),
\'type\' => \'numeric\',
\'compare\' => \'BETWEEN\',
),
array(
\'key\' => \'wpcf-square-meters\',
\'value\' => $value_minmt,
\'type\' => \'numeric\',
\'compare\' => \'>=\',
),
array(
\'key\' => \'wpcf-square-meters\',
\'value\' => $value_maxmt,
\'type\' => \'numeric\',
\'compare\' => \'<=\',
)
);
}
}
if ( isset( $_COOKIE["prelet"] )){
if ($_COOKIE["prelet"] != "yes") {
$value_prelet = 2;
//update_post_meta( $post->ID, \'wpcf-prelet\', $value_prelet );
$prelet_array = array(
\'key\' => \'wpcf-prelet\',
\'value\' => $value_prelet,
\'type\' => \'numeric\',
\'compare\' => \'=\',
);
}
};
if ( isset( $_COOKIE["date"] ) && $date != ""){
$value_date = intval( $_COOKIE["date"] );
//update_post_meta( $post->ID, \'wpcf-completition-date\', $value_date );
$date_array = array(
\'key\' => \'wpcf-completition-date\',
\'value\' => $value_date,
\'type\' => \'numeric\',
\'compare\' => \'=\',
);
};
if ( isset( $sorter )){
if ($sorter == "0") {
$sorter_array = array(
\'meta_key\' => \'wpcf-square-feet\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\'
);
} elseif ($sorter == "1") {
$sorter_array = array(
\'meta_key\' => \'wpcf-square-feet\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\'
);
}
}
?>
这是显示楼层的单体建筑页面
这是单体建筑页面,没有显示楼层
它们都使用相同的代码,具有相同的搜索条件,但不适用于新添加的楼层。
我希望这一切都有意义,会有一个好的灵魂能够帮助我。我必须在英国时间明天早上9点之前交付,我整天都在试图修复它,但没有成功。我非常感谢您的帮助,谢谢。