gpt4 book ai didi

带单选按钮的 PHP 搜索查询

转载 作者:行者123 更新时间:2023-11-29 22:46:01 25 4
gpt4 key购买 nike

我正在尝试向我的搜索查询添加一个可绘图的新语句(单选按钮值是或否)。你能告诉我我的想法是否正确吗?非常感谢。

问候

if ( count( $_GET ) > 0 && isset( $_GET[ 'location' ] ) && isset( $_GET[ 'bedrooms' ] ) && isset( $_GET[ 'price' ] ) && isset($_GET[ 'plot_available' ]) == 'yes' ) {

$location = $_GET[ 'location' ];
$bedrooms = $_GET[ 'bedrooms' ];
$price = $_GET[ 'price' ];
$plot_available = $GET['plot_available'];

我添加了 isset($_GET[ 'plot_available' ] 和搜索查询不起作用。

更新:

    <?php
if ( count( $_GET ) > 0 && isset( $_GET[ 'location' ] ) && isset( $_GET[ 'bedrooms' ] ) && isset( $_GET[ 'price' ] ) && isset($_GET[ 'plot_available' ]) && ($_GET['plot_available'] == 'yes') ) {

$location = $_GET[ 'location' ];
$bedrooms = $_GET[ 'bedrooms' ];
$price = $_GET[ 'price' ];
$plot_available = $GET['plot_available'];

$args = array(
'post_type' => 'development',
'post_status' => 'publish',
'posts_per_page' => '-1',
'location' => $location,
'bedrooms' => $bedrooms,
'price' => $price
);
$query = new WP_Query( $args );

if ( $query->found_posts < 1 ) {

echo '<article><h2>No Results Found</h2>';
echo '<p>No developments have been found for your search query. Please click <a href="' . get_home_url() . '">here</a> to return to the home page and try again with different search parameters.</p></article>';

} else {

echo '<ul id="posts" class="posts">';

if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>

<li class="post clearfix">
<?php
$loc_term = wp_get_post_terms( get_the_id(), 'location' );
$bedroom_term = wp_get_post_terms( get_the_id(), 'bedrooms' );
$price_term = wp_get_post_terms( get_the_id(), 'price-range' );
$house_term = wp_get_post_terms( get_the_id(), 'house-type' );

$link = get_term_link( $loc_term[0] ) . '#' . $post->post_title;

$loc_name = '';
if ( isset( $loc_term[0]->name ) ) {
$loc_name = ' - ' . $loc_term[0]->name;
}

echo '<h2><a href="' . $link . '">' . get_the_title() . $loc_name . '</a></h2>';
if ( isset( $bedroom_term[0] ) ) { echo '<p><strong>' . $bedroom_term[0]->name . '</strong></p>'; }
if ( isset( $price_term[0] ) ) { echo '<p><strong>' . $price_term[0]->name . '</strong></p>'; }
if ( isset( $house_term[0] ) ) { echo '<p><strong>' . $house_term[0]->name . '</strong></p>'; }
?>
</li>

<?php endwhile; endif; wp_reset_query();

echo '</ul>';

}

} else {

echo '<article><h2>Invalid Search</h2>';
echo '<p>Oops, something went wrong with your search. Please click <a href="' . get_home_url() . '">here</a> to return to the home page and try again.</p></article>';

}
?>

我必须仅显示可用的绘图。

最佳答案

替换这一行:

isset($_GET[ 'plot_available' ]) == 'yes'

这样:

isset($_GET[ 'plot_available' ]) && ($_GET['plot_available'] == 'yes')

关于带单选按钮的 PHP 搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29124776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com