Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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_Search_Meta Key - Fatal编程技术网

Php Wordpress自定义搜索结果

Php Wordpress自定义搜索结果,php,wordpress,search,meta-key,Php,Wordpress,Search,Meta Key,我有一个Wordpress自定义搜索表单,用于搜索各种建筑物的楼层。例如,当用户搜索1000到1500平方英尺之间的楼层时,他将得到一个包含所有在这些值之间具有自由楼层空间的建筑物的列表 搜索值存储在Cookie中,因为我需要它们出现在single building页面上 在“单一建筑”页面上,有一个部分显示符合用户搜索条件的楼层 它与我不久前添加的地板配合得很好。当我添加新楼层时,它们不会显示在“单个建筑”页面上 那会是什么?以下是我编写的代码,用于向单个建筑页面显示匹配的楼层: <ta

我有一个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>

这是函数-search.php include

<?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点之前完成,我一整天都在试图修复它,但没有成功。非常感谢您的帮助。

问题在于类别名称,它以数字开头。。!我把它变成了一个字符串,现在它可以工作了。5小时后……

问题是类别名称,它以一个数字开始。。!我把它变成了一个字符串,现在它可以工作了。5小时后