We’re rewarding the question askers & reputations are being recalculated! Read more.
1 of 3

Query custom post type by custom taxonomy (category slug)

I've followed several related solution. But I'm still facing the problem. I've applied the following code for my custom post query by taxonomy (category). But it's not working. I think my problem with 'terms'.

            $terms = get_terms('service_cat');
            $services_post = new WP_Query(array(
                'post_type'         => 'service',
                'posts_per_page'    => -1,
                'tax_query' => array(
                    array(
                        'taxonomy' => 'service_cat',
                        'field' => 'cat1',
                        'terms' => array($terms)
                    )
                ),
            ));

I also tried by the following code

    $services_post = new WP_Query(array(
                'post_type'         => 'service',
                'posts_per_page'    => -1,
                'category_name'     => 'cat1' 
    ))