wordpress问题的Html表单


Html form for wordpress questions

我在wordpress的自定义模板页面中编写代码,我有以下形式,下面的PHP代码就在他旁边。它不工作,我尝试了不同的选项,但仍然没有。

<div class="su-tabs-pane su-clearfix">                  
            <form style="padding: 5px 25px; background:#00ABEC;" action="" method="GET">
                Nume:<input style="width:13.4%;" name="nume"  type="text" value="" />
                Specializare:<input style="width: 13.4%;" name="specializare" type="text" value="" />
                Spital:<input style="width: 13.4%;" name="spital"  type="text" value="" />
                <select name="filter">
                    <option value="ALL">Toate judetele</option>
                    <option value="AB">Alba</option>
                </select>
                <input type="submit" value="Cauta" />
            </form> 
<?php
global $post;
if(isset($_GET["submit"])){
//variabile
$nume_searchq=$_GET["nume"];
$nume_searchq=strlower($nume_searchq);
$spec_searchq=$_GET["specializare"];
$spec_searchq=strlower($spec_search);
$instit_searchq=$_GET["spital"];
$instit_searchq=strlower($instit_searchq);


if($_GET['filter']=="ALL")  {
$results=$wpdb->get_results("SELECT * FROM `wp_posts` WHERE LOWER(post_title) LIKE '%$nume_searchq%' OR LOWER(post_content) LIKE '%$spec_searchq%' OR LOWER(post_content) LIKE '%$instit_searchq%' ORDER by post_title");
}else if($_GET['filter']=="AB")  {
$results=$wpdb->get_results("SELECT * FROM `wp_posts` WHERE LOWER(post_content) LIKE '%Alba%' OR LOWER(post_title) LIKE '%$nume_searchq%' OR LOWER(post_content) LIKE '%$spec_searchq%' OR LOWER(post_content) LIKE '%$instit_searchq%'  ORDER by post_title");
}
$myposts = get_posts( $results);
foreach( $myposts as $post ){ 
     setup_postdata($post);
    echo '<li><a href="' . get_the_permalink() . '"> ' . get_the_title() . ' </a></li>';
}//end_foreach
 wp_reset_postdata();
 }//endIF_submit
 ?>
</div>

它实际上不显示任何东西,我按提交,什么也没发生。如果我有拼写问题或其他问题,请告诉我……谢谢!

您的php代码被包装在这个条件中:

if(isset($_GET["submit"])){...}

但是,您的表单没有具有该name属性(name="submit")的元素,因此该条件始终为false。

将提交按钮更改为:

<input type="submit" name="submit" value="Cauta" />

您可以使用以下代码

<?php

全球美元的帖子;if (isset($_GET["filter"]) &&!空($ _GET["filter")) {

//variabile
$nume_searchq = $_GET["nume"];
$nume_searchq = strtolower($nume_searchq);
$spec_searchq = $_GET["specializare"];
$spec_searchq = strtolower($spec_search);
$instit_searchq = $_GET["spital"];
$instit_searchq = strtolower($instit_searchq);


if ($_GET['filter'] == "ALL") {
    $results = $wpdb->get_results("SELECT * FROM `wp_posts` WHERE LOWER(post_title) LIKE '%$nume_searchq%' OR LOWER(post_content) LIKE '%$spec_searchq%' OR LOWER(post_content) LIKE '%$instit_searchq%' ORDER by post_title");
} else if ($_GET['filter'] == "AB") {
    $results = $wpdb->get_results("SELECT * FROM `wp_posts` WHERE LOWER(post_content) LIKE '%Alba%' OR LOWER(post_title) LIKE '%$nume_searchq%' OR LOWER(post_content) LIKE '%$spec_searchq%' OR LOWER(post_content) LIKE '%$instit_searchq%'  ORDER by post_title");
}
$myposts = get_posts($results);
foreach ($myposts as $post) {
    setup_postdata($post);
    echo '<li><a href="' . get_the_permalink() . '"> ' . get_the_title() . ' </a></li>';
} //end_foreach
wp_reset_postdata();

}//endIF_submit祝辞;