使用以下代码来实现这一点
function custom_search_where( $where )
{
if(isset($_POST['your-custom-serchtext'])){
$where = "post_content Like %$_POST['your-custom-serchtext']% ", $where );
}
return $where;
}
$query = new WP_Query( array('post_type' => 'faq-item','tax_query' => array(
array(
'taxonomy' => 'faq-group',
'field' => 'slug',
'terms' => 'australia '
)
)) );
add_filter('posts_where', 'custom_search_where' );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
} else {
// no posts found
}
remove_filter( 'posts_where', 'custom_search_where' );
我没有测试过这段代码,但我希望它对你有用。