1

I have custom posts articles with custom taxonomy tags-articles, I need search all posts with have the term in title, or taxonomy associated with same title (or partial title):

Example os published posts:

Post: [1]: Red car is very fast
Taxonomy: whell, faster

Post: [2]: Blue car is bigger

Post: [3]: The truck have many whells
Taxonomy: big, faster

Post: [4]: All peoples are very happy

Post: [5]: The city have many automobile
Taxonomy: car, bikes

My custom query (return all posts, not just filtered):

$searchTerm = 'fast'; // needs return: Posts: [1], [3]
$searchTerm = 'car'; // needs return: Posts: [1], [2], [5]
$searchTerm = 'bi'; // needs return: Posts [2], [3], [5]

$args = array(
    'post_type'   => array( 'articles' ),
    'post_status' => array( 'publish' ),
    's'           => $searchTerm,
    'nopaging'    => true,
    'order'       => 'ASC',
    'orderby'     => 'title',
    'meta_query'  => array(
        'relation' => 'OR',
        array(
            'taxonomy' => 'tags-articles',
            'terms'    => $searchTerm,
            'field'    => 'name',
            'compare' => 'LIKE',
        ),
    ),
);

$search = new WP_Query( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.