wordpress php在同一页面上获取搜索结果(更改表单操作网址)

时间:2015-12-30 02:14:13

标签: php wordpress forms

所以我有这个搜索过滤器的东西,但我希望搜索结果与过滤器一样显示。然而,它不断带我到一个单独的搜索页面来显示结果。

我认为我只需要将表单操作设置为当前网址或某个网页网址或固定链接。 <form action="http://localhost/siennahomes_www/property-search-sienna/>

理想情况下我希望它是

<form action="http://localhost/siennahomes_www/home-designs/>

我已尝试输入绝对链接进行测试,但它似乎被php函数覆盖。它经常停留在 无论我尝试多少。

模板中的代码位是:

高级搜索:

<?php

global $theme_search_url;

$theme_search_url = get_option('theme_search_url');

global $theme_search_fields;

$theme_search_fields= get_option('theme_search_fields');

if( !empty($theme_search_url) && !empty($theme_search_fields) && is_array($theme_search_fields) ):

    ?>

    <section class="advance-search ">

        <?php

        $home_advance_search_title= get_option('theme_home_advance_search_title');

        if(!empty($home_advance_search_title)){

            ?><h3 class="search-heading"><i class="fa fa-search"></i><?php echo $home_advance_search_title; ?></h3><?php

        }

        get_template_part('template-parts/search-form');

        ?>

    </section>

    <?php

endif;

?>

家居设计页面:

<?php

/*

*   Template Name: home designs test

*/

get_header();

/* Theme Home Page Module */

$theme_search_module = get_option('theme_search_module');

?>

    <!-- Content -->

    <div class="container contents">

        <div class="row">

            <div class="span12">

                <!-- Main Content -->

                <div class="main">

                    <?php

                    /* Advance Search Form */

                    get_template_part('template-parts/advance-search-test');

                    ?>

                    <section class="property-items">

                        <div class="search-header">

                            <?php get_template_part('template-parts/sort-controls'); ?>

                        </div>

                        <div class="property-items-container clearfix">

                            <?php

                            /* List of Properties on Homepage */

                            $number_of_properties = intval(get_option('theme_properties_on_search'));

                            if(!$number_of_properties){

                                $number_of_properties = 4;

                            }

                            $search_args = array(

                                'post_type' => 'property',

                                'posts_per_page' => $number_of_properties,

                                'paged' => $paged

                            );

                            // Apply Search Filter

                            $search_args = apply_filters('real_homes_search_parameters',$search_args);

                            $search_args = sort_properties($search_args);

                            $search_query = new WP_Query( $search_args );

                            if ( $search_query->have_posts() ) :

                                $post_count = 0;

                                while ( $search_query->have_posts() ) :

                                    $search_query->the_post();

                                    /* Display Property for Search Page */

                                    get_template_part('template-parts/property-for-home');

                                    $post_count++;

                                    if(0 == ($post_count % 2)){

                                        echo '<div class="clearfix"></div>';

                                    }

                                endwhile;

                                wp_reset_query();

                            else:

                                ?><div class="alert-wrapper"><h4><?php _e('No Properties Found!', 'framework') ?></h4></div><?php

                            endif;

                            ?>

                        </div>

                        <?php theme_pagination( $search_query->max_num_pages); ?>

                    </section>

                </div><!-- End Main Content -->

            </div> <!-- End span12 -->

        </div><!-- End  row -->

    </div><!-- End content -->

<?php get_footer(); ?>

搜索形式:

<div class="as-form-wrap">
<form class="advance-search-form clearfix" action="<?php global $theme_search_url; echo $theme_search_url; ?>" method="get">
<?php if ( in_array ( 'keyword-search', $theme_search_fields ) ) {
        ?>
<div class="option-bar large">
<label for="keyword-txt"><?php _e('Keyword', 'framework'); ?></label>
<input type="text" name="keyword" id="keyword-txt" value="<?php echo isset ( $_GET['keyword'] ) ? $_GET['keyword'] : ''; ?>" placeholder="<?php _e('Any', 'framework'); ?>" />
        </div>
        <?php
    }

    if ( in_array ( 'property-id', $theme_search_fields ) ) {
        ?>
        <div class="option-bar large">
            <label for="property-id-txt"><?php _e('Property ID', 'framework'); ?></label>
            <input type="text" name="property-id" id="property-id-txt" value="<?php echo isset($_GET['property-id'])?$_GET['property-id']:''; ?>" placeholder="<?php _e('Any', 'framework'); ?>" />
        </div>

我怀疑罪魁祸首是高级搜索页面上的这一行:

$theme_search_url = get_option('theme_search_url');

0 个答案:

没有答案