Looking for an option to use the AnsPress Plugin to enable users to just post ideas, in addition to the regular Question Answer Forum. Looking to add a custom field to indicate whether user wants to post idea or ask question, and if the user selects “Post Idea”, then want the Answer Block to be removed (or not displayed) when the Idea is published. Other users can comment and vote on the idea, but shouldn’t be able to answer (since that doesn’t apply in this scenario). Please suggest easiest way to implement this feature.
First of all, Big Thanks to Rahul for putting together this great plugin. Really appreciate his efforts! Well, I figured out the customization and here is what I did to implement it. Posting this for the benefit of the wider AnsPress community:
Added a custom checkbox that users are required to check when they post an idea. Added custom field using the hook as follows:
add_filter( ‘ap_question_form_fields’, ‘my_function_name_with_custom_field_added’ );
Sample code on adding custom fields can be found at the link below:
Added code to save the value from the custom checkbox field. The value will be saved in the meta_value column for the meta_key specified in your custom code, and saved to wp_postmeta table for the post_id. Added the following code:
add_action( ‘ap_processed_new_question’, ‘my_custom_save_method’ , 10, 2 );
add_action( ‘ap_processed_update_question’, ‘my_custom_save_method’ , 10, 2 );
Used the update_post_meta method inside my custom save function (my_custom_save_method) and passed the post_id, meta_key and meta_value parameters as follows:
update_post_meta($post_id, ‘meta_key_name’, ‘meta_key_value’);
Changed the Ask Page title to ‘Ask Question / Post Idea’.
Changed the Ask Page title to ‘Update Question’ or ‘Update Idea’ as applicable when user edits an existing question or idea.
Made the button text on Ask Page as generic – ‘Submit’ (for new posts) and ‘Update’ (for updating existing posts).
Appended the flag ‘[IDEA]’ to the question title for easy identification of ideas. See link below for guidance on how to implement this:
Modified the Ask Button text on the Anspress base page to ‘Ask Question / Post Idea’. This needed a change to the core Anspress file – (\plugins\anspress-question-answer\includes\theme.php). Added a new filter ‘ap_ask_btn_text’ (similar to the existing filter ‘ap_ask_btn_link’) inside function ap_get_ask_btn() in theme.php file. I’ll coordinate with Rahul to get this change via GitHub to the core Anspress code so it should be easy to customize the Ask Button text for everyone using the new filter.
Please note that all custom code should be added to your child theme’s function.php file. Hope it is clear. Thank you!