我正在尝试向搜索查询中添加一个新的语句,该语句可用于情节(单选按钮值为“是”或“否”)。你能告诉我我的思维方式是否正确。非常感谢。
问候
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 - 带单选按钮的PHP搜索查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29124776/