Use WP_Query to get list of questions with a certain tag

Solved4.21K viewsIssuesAnspress
0

I am trying to get a list of questions that all have a certain tag. I’m using WP_Query to do this. However, the following code doesn’t filter on the tag values:

 

$args = array(
‘post_status’ => array( ‘publish’ ),
‘post_type’ => ‘question’,
‘suppress_filters’ => true, //Bypasses content filtering by Groups plugin
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘tag’ => ‘my-tag’,
‘ignore_sticky_posts’ => true
);

$query = new WP_Query( $args );

// loop through the posts and build our endpoint data arrays
if ( $query->have_posts() ) {…do stuff … }

 

Is it possible to do this?

Question is closed for new answers.
selected answer
1

Hello, it is possible!

To show questions from the category use:

$query = new WP_Query( array(
‘post_type’ => ‘question’,
‘question_category’ => ‘category-slug’,
) );
while ( $query->have_posts() ) {
$query->the_post();
the_title();
}

To show questions from the tag use:

$query = new WP_Query( array(
‘post_type’ => ‘question’,
‘question_tag’ => ‘tag-slug’,
) );
while ( $query->have_posts() ) {
$query->the_post();
the_title();
}

selected as best answer