Title: Create custom question type
Last modified: November 3, 2021

---

# Create custom question type

 *  [rookiewp](https://wordpress.org/support/users/rookiewp/)
 * (@rookiewp)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/create-custom-question-type/)
 * I’m developing extended quiz functions and would appreciate to use Learnpress
   as the LMS frame (using e.g. a plugin as “Add On” for lp). My problem: Is seems
   to me that the predefined questiontypes are hard coded in js, means no new question
   type can be easily added. Example: “single_compare”: One question with one correct
   answer to be provided as string. Choice of “single_compare”-type should be possible
   in admin-area (question post-type) and integration of specific view in front-
   end with input field. Is there any hint you can give (e.g. using hooks)? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [brianvu-tp](https://wordpress.org/support/users/briantp/)
 * (@briantp)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/create-custom-question-type/#post-15034918)
 * Hi,
 * First, you should create a class extend LP_Question then set protected $_question_type
   = ‘name_uinque’; // should start with prefix by name of your plugin
 * Add hooks:
 *     ```
       add_filter(
       	'learn-press/question-types',
       	function( $types ) {
       		$types['name_uinque'] = esc_html__( 'Sorting Choice', 'learnpress-sorting-choice' );
   
       					return $types;
       				}
       			);
   
       			add_filter(
       				'learn-press/default-question-types-support-answer-options',
       				function( $data ) {
       					$data[] = 'name_uinque';
   
       					return $data;
       				}
       			);
       ```
   
 * Then you can write code in backend and frontend
 *  Thread Starter [rookiewp](https://wordpress.org/support/users/rookiewp/)
 * (@rookiewp)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/create-custom-question-type/#post-15042284)
 * Thanks for the helpful hint: Using the filters the new question-type appeared
   in the backend question-type choice list.
 * However I didn’t succeed in extending properly the LP_Question class. What I 
   did first was to copy “class-lp-question-single-choice.php” as an example for
   the extension and then to change filename, classname and question-type name to
   the new one. But when I choose in backend the new type the typical “single-choice”
   view (with radio buttons) doesn’t appear. Is there any other datastructure to
   double from “single-choice”?
    Question for me is also how the extended LP_Question-
   class will be called. I included the file with the new class within my AddOn 
   by “required_once” after lp has been loaded, but how does lp calls the extended
   class and uses it for front and backend when the new question type has been chosen?
 * For eventual further questions: Is there any tutorial for AddOn development in
   LP (e.g. explaining the datastructure and extendable classes)? I could only find
   the “Rest API” and a list of actions and filters, but to find the right interfaces
   I’m doing deep-dives in lp-code and I’m greatful for getting your good hints.
   
   Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Create custom question type’ is closed to new replies.

 * ![](https://ps.w.org/learnpress/assets/icon-256x256.gif?rev=3254420)
 * [LearnPress - WordPress LMS Plugin for Create and Sell Online Courses](https://wordpress.org/plugins/learnpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/learnpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/learnpress/)
 * [Active Topics](https://wordpress.org/support/plugin/learnpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/learnpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/learnpress/reviews/)

## Tags

 * [question](https://wordpress.org/support/topic-tag/question/)

 * 2 replies
 * 2 participants
 * Last reply from: [rookiewp](https://wordpress.org/support/users/rookiewp/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/create-custom-question-type/#post-15042284)
 * Status: not resolved