• Hi Good day!

    I want to customize the search functionality of the website i am currently developing,

    I have a text field called ‘Search for: ‘

    and two dropdowns:

    1st dropdown: ‘Custom Taxonomy 1’

    2nd dropdown: ‘Custom Taxonomy 2’

    The user will enter his desired keywords and then chooses for the combination of custom taxonomy 1 terms ‘and’ custom taxonomy terms matching that keywords he entered.

    I’ve make sure i have pass my parameters correctly using $_GET;

    I want to use Worpdress WP Query in this, currently I have this code in my search.php

    <?php
    $args = array(
    'tax_query' => array(
    'relation' => 'AND',
    array(
    'taxonomy' => 'custom_taxonomy1', /** region **/
    'field' => 'slug',
    'terms' => 'my-term1'
    ),
    array(
    'taxonomy'  => 'custom_taxonomy2',
    'field'  => 'slug',
    'terms'  =>  'my-term2'
    )
    ),
    'post_title' => $_GET['s']
    );
    
    $listing = new WP_Query( $args );
    
    while ( $listing->have_posts() ) : $listing->the_post();
            /** The contents **/
    endwhile;
    
    ?>

    and it seems to ignore my post title.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Joseph G.

    (@dunhakdis)

    Just trying ‘post_title’ => $_GET[‘s’] , but no luck so far.

    Thread Starter Joseph G.

    (@dunhakdis)

    anyone?

    Thread Starter Joseph G.

    (@dunhakdis)

    Never mid guys, I got it.

    <?php
    $args = array(
    'tax_query' => array(
    'relation' => 'AND',
    array(
    'taxonomy' => 'custom_taxonomy1', /** region **/
    'field' => 'slug',
    'terms' => 'my-term1'
    ),
    array(
    'taxonomy'  => 'custom_taxonomy2',
    'field'  => 'slug',
    'terms'  =>  'my-term2'
    )
    ),
    'post_title' => $_GET['s']
    );
    
    $listing = new WP_Query( $args );
    
    while ( $listing->have_posts() ) : $listing->the_post();
            /** The contents **/
    endwhile;
    
    /** in functions.php **/
    
    function additional_conditions ( $where ) {
    	global $wpdb;
    
    	$additional_condition = "MATCH ($wpdb->posts.post_title, $wpdb->posts.post_content) AGAINST ('Etobicoke')";
    	return $where . ' AND 2=2 AND ' . $additional_condition;
    }
    add_filter( 'posts_where' , 'additional_conditions' );
    ?>
    Thread Starter Joseph G.

    (@dunhakdis)

    2=2 is nothing but useless condition..

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP Query include post title as 'Search' With two custom taxonomies’ is closed to new replies.