asked 3 years ago

I need to know, how i can get the questions and answers from a user. I use the DWQ&A Pro plugin and the Userpro plugin.
Now my problem is, i  want to display the questions and answers of a user on his profile card. I have tried to filter the questions and answers but i dont no how i filter their with the Userpro plugin.
I have tried to do that in this way:
first i have enter the shortcode [dwqa-list-questions] in the profile page where is possible to edit the wordpress page from dashboard, than i added the following code to function.php from my theme:
add_filter( ‘dwqa_prepare_archive_posts’, ‘dwqa_refilter_question’ );
function dwqa_refilter_question( $args = null ) {
if ( isset( $args ) ){
// change 0 to page id you had place other archive page contain shortcode [dwqa-list-questions]
if ( is_page( 0) ) {
$question_args = array(
‘post_type’ => ‘dwqa-questions’,
‘posts_per_page’ => 5, //Number of Questions
‘post_type’ => ‘dwqa-questions’, //Get the questions only
‘post_author’ => get_current_user_id(), // the ID of user
‘post_status’ => ‘publish’
// this will return array with 5 answer’s ids
$questions = get_posts( $question_args );
$question_lists = array();
foreach( $questions as $question_id ) {
$question_lists[] = get_post_meta( $question_id, ‘_question’, true );
$args[‘post__in’] = $question_lists;
return $args;
i have tried in serveral ways to filter the question, but i dont know how i can get the user id.
I want only to display the questions of a user under his profile card in his profile page.
Maybe is there a other way to do that?

1 Answers
answered 3 years ago

I have checked your code and I think you can try the following code.

add_filter( 'dwqa_prepare_archive_posts', 'dwqa_refilter_question' );
function dwqa_refilter_question( $args = null ) {
 if ( isset( $args ) ){
 $args['author'] = get_current_user_id();
 $args['post_type'] = 'dwqa-question';
 // $args['post_type'] = 'dwqa-answer'; //get answer only
 //$args['post_type'] = array('dwqa-question', 'dwqa-answer' ); //get both question and answers
 return $args;

Also, you can send me your plugin for further checking, we will check and integrate the Userpro plugin with the Q&A plugin in the next version.
Our email:

Powered by DW Question & Answer Pro