• Resolved mubasher99

    (@mubasher99)


    1- How can I show total number of quiz questions count. like wp_count_posts()
    2- how can I Show the total Quiz Questions posted by authors. I have tried this but didn’t get any result.
    <?php wp_list_authors(‘orderby=post_count&post_type=post_type_questionna&order=DESC&number=10&optioncount=1&taxonomy=quiz’); ?>

    Please Guide

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Harmonic Design

    (@harmonic_design)

    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
    Thread Starter mubasher99

    (@mubasher99)

    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

    Plugin Author Harmonic Design

    (@harmonic_design)

    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.

    Thread Starter mubasher99

    (@mubasher99)

    Thank you very much for your cooperation dear.. Love your work dear.. <3

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Need Help in coding’ is closed to new replies.