Is it possible to add tags for answers?

5.29K viewsUpdates
0

Hi, Rahul.

 

We wonder whether it is possible to apply tags feature on answers like questions.

If possible, please give us directions.

 

Thanks

1

@jmoon: have a look at the wp-content/plugins/tags-for-anspress/tags-for-anspress.php file.

In there you’ll finde the following hooks:

add_action('ap_ask_form_fields', array($this, 'ask_from_tag_field'), 10, 2);
add_action('ap_ask_fields_validation', array($this, 'ap_ask_fields_validation'));
add_action( 'ap_processed_new_question', array($this, 'after_new_question'), 0, 2 );
add_action( 'ap_processed_update_question', array($this, 'after_new_question'), 0, 2 );

Simply copy & paste those and the corresponding functions. To make a clear separation between questions & answers, make sure you also copy & rename the function names. I’ve done it like the following:

add_action('ap_answer_form_fields', array($this, 'answer_form_tag_field'), 10, 2);
add_action('ap_answer_fields_validation', array($this, 'ap_answer_fields_validation'));
add_action( 'ap_processed_new_answer', array($this, 'after_new_answer'), 0, 2 );
add_action( 'ap_processed_update_answer', array($this, 'after_new_answer'), 0, 2 );

Also, If you would like to make selecting tags optional you have to remove the ap_ask_fields_validation or the ap_answer_fields_validation hooks.

@Rahul, I just noticed, (from above code snippet) you have written “ask_from_tag_field” in the first line instead of “ask_FORM….”. Is it typo or intentional?

1

+1 to see this feature configurable in the official plugin 🙂

0

Yes, it can be easily implimented. You can have a look at tags plugin and copy form fields of question and add them answer form hook.

Thank you for help!
By the way, we are really sorry but we are not sure which field to copy and where to paste.

What is the answer form hook? Please show how to do it.

Thanks a lot.