Total number of questions in a quiz.
$quiz_id = 5; // change to the quiz ID
$args = array(
'post_type' => 'post_type_questionna',
'posts_per_page' => -1, // get all posts
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'quiz',
'field' => 'term_id',
'terms' => $quiz_id
)
)
);
$q = new WP_Query( $args );
echo $q->post_count; // prints total questions in that quiz
how can I Show the total Quiz Questions posted by authors. I have tried this but didn’t get any result.
Not tested, but something like this should work.
$author_id = 0; // change to the ID of the author you want to count
$args = array(
'post_type' => 'post_type_questionna',
'posts_per_page' => -1,
'author' => $author_id
);
$q = new WP_Query( $args );
echo $q->post_count; // prints total questions created by author
Thank you dear for the help. One last Question:
What if I want to know “Total number of Questions from all the Quizzes”. what would be the code then. Because $quiz_id cant work here i think..
Thanks is advance
For that, you can just remove the tax_query array since it’s not needed. Just keep the post_type and posts_per_page parameters. This will show the total # of questions across ALL quizzes.
Thank you very much for your cooperation dear.. Love your work dear.. <3