WordPress问题的HTML表单

qyzbxkaa  于 2023-05-12  发布在  WordPress
关注(0)|答案(2)|浏览(137)

我写的代码在一个自定义模板页面从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>

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

qaxu7uf2

qaxu7uf21#

你的php代码被 Package 在这个条件中:

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

但是,表单中没有具有该name属性(name="submit")的元素,因此条件始终为false。
将提交按钮更改为:

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

inn6fuwd2#

你可以用这个代码

<?php

global $post; if(isset($_GET[“filter”])&&!public void run($_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();

} //提交>

相关问题