• Resolved daviddorsettech

    (@daviddorsettech)


    Hi,

    Just a quick one, I was wondering it is possible to use the quiz name in the shortcode?

    I’m considering using the post title to retrieve the correct quiz in the template to make the process simpler for a user. Would this be possible or would I have to name the post the id of the quiz? (not very user friendly).

    Or perhaps is there a way I can get the id using the name of the quiz?

    Kind Regards,
    David Tattersall

Viewing 1 replies (of 1 total)
  • Thread Starter daviddorsettech

    (@daviddorsettech)

    Hi,

    If anyone comes across this question, I found the answer myself after a little digging and here is the solution I came up with.

    To save users the confusion of shortcodes. I set up a custom post type called quiz/quizzes

    I then wanted them to be able set up a quiz using this plugin. Then all they’d need to do is add a quiz post with the same name and it would automatically grab the correct quiz and display it on that post page.

    Here you go:
    $quiz = get_term_by(‘name’, esc_html(get_the_title()), ‘quiz’, OBJECT);
    //$quiz gets the term(specific quiz) by using the name field derived from the
    //title of the post from the quiz taxonomy. returns object.
    echo do_shortcode(“[HDquiz quiz = ‘”. $quiz->term_id .”‘]”);
    //output the shortcode on the template single-quiz.php using the term_id from
    //the $quiz object. et voila

    Kind Regards,
    David Tattersall
    Dorset Tech

Viewing 1 replies (of 1 total)

The topic ‘Using Quiz name in shortcode?’ is closed to new replies.