简体   繁体   中英

Include Taxonomy Terms in WP_Query

I am building a search page with a new instance of wp_query I am passing a string into s to get a part number which is currently a taxonomy term. Is there a way to include to the taxonomy term in a custom wp_query ? Happy help would be appreciated.

You can query posts by a taxonomy value like in the example below:

$query_string = 'francis';

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'people',         // your taxonomy name
            'field'    => 'slug',
            'terms'    => $query_string,    // the slug you want to search for - which in your case is passed through the query string
        ),
    ),
);
$query = new WP_Query( $args );

To access the query string, use get_search_query() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM