genesisorgnix
asked 11 years ago

Hi, can you make the User just see all the questions that he asked when he login? Thanks.

5 Answers
DominicStaff
answered 11 years ago

Hello Genesisorgnix !
Currently, Our DW Q&A plugin does not yet support for Users just see all the questions asked when login. However, You can use the Buddypress plugin to get a list of all the questions for a user  when you click  over the username.
If you want to display Question tab have style as our demo, You can open the bp-custom.php file, replace all the code in the bp-custom.php  file with new code:

 <?php
if ( function_exists('dwqa_plugin_init') && function_exists('bp_is_active')) {
  /*-----------------------------------------------------------------------------------*/
  /*  Setup Questions in BuddyPress User Profile
  /*-----------------------------------------------------------------------------------*/
  add_action( 'bp_setup_nav', 'dw_simplex_bp_nav_adder' );
  function dw_simplex_bp_nav_adder() {
     bp_core_new_nav_item(
      array(
        'name' => __('Questions', 'dw-simplex'),
        'slug' => 'questions',
        'position' => 21,
        'show_for_displayed_user' => true,
        'screen_function' => 'questions_list',
        'item_css_id' => 'questions',
        'default_subnav_slug' => 'public'
      ));
  }

  function questions_list() {
    add_action( 'bp_template_content', 'profile_questions_loop' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  }

  function profile_questions_loop() {
    global $dwqa_options;
    $submit_question_link = get_permalink( $dwqa_options['pages']['submit-question'] );
    $questions = get_posts(  array(
      'posts_per_page' => -1,
      'author'         => bp_displayed_user_id(),
      'post_type'      => 'dwqa-question'
    ));
    if( ! empty($questions) ) { ?>
      <div class="dwqa-container">
        <div class="dwqa-list-question">
          <div class="dw-question" id="archive-question">
            <?php foreach ($questions as $q) { ?>
            <article id="question-18267" class="dwqa-question">
                <header class="dwqa-header">
                    <a class="dwqa-title" href="<?php echo get_post_permalink($q->ID); ?>" title="Permalink to <?php echo $q->post_title ?>" rel="bookmark"><?php echo $q->post_title ?></a>
                    <div class="dwqa-meta">
                        <?php dwqa_question_print_status($q->ID); ?>
                        <span><?php echo get_the_time( 'M d, Y, g:i a', $q->ID ); ?></span>
                        &nbsp;&nbsp;&bull;&nbsp;&nbsp;
                        <?php echo get_the_term_list( $q->ID, 'dwqa-question_category', '<span>Category: ', ', ', '</span>' ); ?>
                    </div>
                </header>
            </article>
            <?php } ?>
          </div>
        </div>
      </div>
    <?php } else { ?>
    <div class="info" id="message">
      <?php if( get_current_user_id() == bp_displayed_user_id() ) : ?>
        Why don't you have question for us. <a href="<?php echo $submit_question_link ?>">Start asking</a>!
      <?php else : ?>
        <p><strong><?php bp_displayed_user_fullname(); ?></strong> has not asked any question.</p>
      <?php endif; ?>
    </div>
    <?php }
  }

  /*-----------------------------------------------------------------------------------*/
  /*  Record Activities
  /*-----------------------------------------------------------------------------------*/
  // Question
  function dw_simplex_record_question_activity( $post_id ) {
    $post = get_post($post_id);
    if(($post->post_status != 'publish') && ($post->post_status != 'private'))
      return;

    $user_id = get_current_user_id();
    $post_permalink = get_permalink( $post_id );
    $post_title = get_the_title( $post_id );
    $activity_action = sprintf( __( '%s asked a new question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    $content = $post->post_content;
    $hide_sitewide = ($post->post_status == 'private') ? true : false;

    bp_blogs_record_activity( array(
      'user_id' => $user_id,
      'action' => $activity_action,
      'content' => $content,
      'primary_link' => $post_permalink,
      'type' => 'new_blog_post',
      'item_id' => 0,
      'secondary_item_id' => $post_id,
      'recorded_time' => $post->post_date_gmt,
      'hide_sitewide' => $hide_sitewide,
    ));
  }
  add_action( 'dwqa_add_question', 'dw_simplex_record_question_activity');

  //Answer
  function dw_simplex_record_answer_activity( $post_id ) {
    $post = get_post($post_id);

    if($post->post_status != 'publish')
      return;

    $user_id = $post->post_author;

    $question_id = get_post_meta( $post_id, '_question', true );
    $question = get_post( $question_id );

    $post_permalink = get_permalink($question_id);
    $activity_action = sprintf( __( '%s answered the question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $question->post_title . '</a>' );
    $content = $post->post_content;

    $hide_sitewide = ($question->post_status == 'private') ? true : false;

    bp_blogs_record_activity( array(
      'user_id' => $user_id,
      'action' => $activity_action,
      'content' => $content,
      'primary_link' => $post_permalink,
      'type' => 'new_blog_post',
      'item_id' => 0,
      'secondary_item_id' => $post_id,
      'recorded_time' => $post->post_date_gmt,
      'hide_sitewide' => $hide_sitewide,
    ));
  }
  add_action( 'dwqa_add_answer', 'dw_simplex_record_answer_activity');
  add_action( 'dwqa_update_answer', 'dw_simplex_record_answer_activity');

  //Comment
  function dw_simplex_record_comment_activity( $comment_id ) {
    $comment = get_comment($comment_id);
    $user_id = get_current_user_id();
    $post_id = $comment->comment_post_ID;
    $content = $comment->comment_content;

    if(get_post_type($post_id) == 'dwqa-question') {
      $post = get_post( $post_id );
      $post_permalink = get_permalink( $post_id );
      $activity_action = sprintf( __( '%s commented on the question: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
      $hide_sitewide = ($post->post_status == 'private') ? true : false;
    } else {
      $post = get_post( $post_id );
      $question_id = get_post_meta( $post_id, '_question', true );
      $question = get_post( $question_id );
      $post_permalink = get_permalink( $question_id );
      $activity_action = sprintf( __( '%s commented on the answer at: %s', 'dw-simplex' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . $question->post_title . '</a>' );
      $hide_sitewide = ($question->post_status == 'private') ? true : false;
    }

    bp_blogs_record_activity( array(
      'user_id' => $user_id,
      'action' => $activity_action,
      'content' => $content,
      'primary_link' => $post_permalink,
      'type' => 'new_blog_comment',
      'item_id' => 0,
      'secondary_item_id' => $comment_id,
      'recorded_time' => $comment->comment_date_gmt,
      'hide_sitewide' => $hide_sitewide,
    ));
  }
  add_action( 'dwqa_add_comment', 'dw_simplex_record_comment_activity');
}

Hope this helps !

genesisorgnix
replied 11 years ago

which specific Buddy Press Plugin? Thanks.

genesisorgnix
replied 11 years ago

oh got it! THanks!

genesisorgnix
replied 11 years ago

sorry but i have downloaded the BuddyPress plugin but i can’t find the bp-custom.php ? Please advise. Thanks.

DominicStaff
answered 11 years ago

Genesisorgnix !
Go to your theme folder (wp-content/themes/[theme-name]), and create a new folder, name it “buddypress”. Inside your new folder, create a new file: “bp-custom.php”.

Genesis Alvarez
replied 11 years ago

@Dominic

(genesisorgnix here, i forgot my password and my “forgot password email” doesnt show the link.)

I have followed your instructions from above, but still doesn’t work. Any advise? Please help. Thanks.

WP: 3.8.1
DW Q&A: 1.1.1
BuddyPress: 1.9.2

Dominic Staff
replied 11 years ago

After installing BuddyPress. Go to your theme folder (wp-content/themes/[theme-name]), and create a new folder, name it “buddypress”. Inside your new folder, create a new file: “bp-custom.php”.
Now, open up the new file in notepad or any code editor, and copy/paste the code in the answer before.
If you still face the issue you can send me your FTP (via private answer) for further checking.

Mike Burgess
replied 11 years ago

I am using iThemes ‘Builder’ with ‘air’ child theme. Where would I upload the buddypress folder?

themes/Builder
OR
themes/Builder-Air-Custom

and when I rename the template in the file what should I use as the template instead of dw_simplex

Regards
Mike

Guru
replied 11 years ago

themes/Builder-Air-Custom as the folder

and dw_Builder-Air-Custom as the theme name

Mike
replied 11 years ago

Thank you Guru. I will give it another go 🙂

Mike
replied 11 years ago

Didn’t work for me. That is the second time I have tried this without success.

I am putting the edited functions.php file in the child theme folder (themes/Builder-Air-Custom). Is that correct?
Guru you said to put dw_Builder-Air-Custom
Why do I put the dw_

Guru
replied 11 years ago

Perhaps you need the following to your child theme functions.php too;

include_once get_template_directory().’/buddypress/bp-custom.php’;

Mike
replied 11 years ago

Yes I have already tried that Guru. I have tried everything. I must be using the wrong functions.php file or something.

Not sure I should be putting dw_ in front of my template name in the file.

Perhaps it is the Builder theme. I have had a few issues with it. If I had know about Design Wall when I started the site I probably would have used one their themes.

Carlos takemura
answered 11 years ago

@Dominic – thank you for sharing this idea.
 
I think a lot of confusion is arising when people see your integration of DW Q&A as used for DesignWall.com, and then they see the demo and download and want the same implementation as DesignWall.com 
 
But they don’t realise it needs BuddyPress in order to get the same functionality.
 
If you haven’t thought about it already, or even done it already, then perhaps a tutorial guide on how to integrate DW Q&A with BP would be a good idea as it’s difficult to find all the info scattered throughout the Questions & Answers here.
 
Just an idea 😉

DominicStaff
answered 11 years ago

Hi Carlos !
Thanks for your feedback. We are updating a tutorial guide on how to integrate DW Q&A with Buddypress and will release it as soon as possible in the document guide site.

Guru
answered 11 years ago

This would be a great boost to your already very useful plugin @Dominic

DominicStaff
answered 11 years ago

Hi Genesis !
Please change ‘dw_simplex’ & ‘dw-simplex’ to your theme name Step 3: Open the function file of your theme (wp-content/themes/[theme-name]/functions.php), and add this code in (somewhere at top of the file):

 
include_once get_template_directory().'/buddypress/bp-custom.php';

Final step: Save the files and go to your profile page to see list of all questions on the new Questions tab. Please try and let us know the results! If you still face the issue, Please send me your username & password your site for further checking.
Hope this helps !

Genesis Alvarez
replied 11 years ago

Hi Dominic, Thanks for your help! i've made it to work, but the thing now is im getting error when adding and deleting wordpress category. Any advise to avoid that? Thank you.

Ejaz Ahmed
answered 11 years ago

Hi I have implemented this code but could not achieve the result like of your site. Can you help me out how can I achieve the same results as of yours site have. My Site is http://www.hrden.com

Guru
replied 11 years ago

I just checked your url. The solution provided above creates a questions tab unders member profile. Here is a link: http://www.hrden.com/members/team-hrden/questions/

Ejaz Ahmed
answered 11 years ago

Hi Guru,
Thanks for your reply. In the same way Can i create a tab for “Posts” similar to “Questions”?
Regards,

Kido D
answered 11 years ago

Hi Ejaz,
I have not heard of that being an option, however since we are simply providing coding Questions tab for the BuddyPress plugin, you could definitely reach out to them directly to see if there is an add-on or solution that would accomplish this.
Cheers!

Rahul Morya
answered 10 years ago

Hey thanks for the code . It worked for me . But it is displayed under profile> questions 
and not in the tabular form as dwqa displays http://cmspioneer.com/designwall/question/

I need to display user asked question under a separate page say questions-you-asked.php 
in the same tabular form as it is displayed in the general questions page . 

Please help me out 

Thanks
 

DominicStaff
answered 10 years ago

At the moment, DW Q&A does not yet support to display user asked question under a separate page. you only possible display question for each user when you click on username.

sharma chelluri
answered 10 years ago

How to create a new tab in the Buddypress Profile link with user posts?
1) create a folder /buddypress/ under your theme directory
2) create bp-custom.php file in the directory.
Now your theme folder has a structure –>
your Theme Directory/buddypress/bp-custom.php

2.1 Include bp-custom.php file in your theme function.php using include or include_once php function.
3) create three actions to get the tab working(Don’t do any thing yet. Just explaining the theory)
=> add_action( ‘bp_setup_nav’, ‘buddyboss_child_bp_nav_adder’ );
=> add_action( ‘bp_template_content’, ‘profile_buddyboss_child_loop’ );
=> bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );

4) First you need to apply action >> buddyboss_child_bp_nav_adder << to the hook >> bp_setup_nav<< .
5) The function definition looks like this.
function buddyboss_child_bp_nav_adder() {
global $bp;
$post_count = count_user_posts_by_type( $bp->displayed_user->id );
bp_core_new_nav_item(
array(
‘name’ => sprintf( __( ‘Articles <span>%d</span>’, ‘my-poems’ ), $post_count ),
‘slug’ => ‘Articles’,
‘position’ => 250,
‘show_for_displayed_user’ => true,
‘screen_function’ => ‘buddyboss_child_list’,
‘item_css_id’ => ‘articles’,
‘default_subnav_slug’ => ‘public’
));
}

6) The important part in the above function is =>>screen_function with name ===>>buddyboss_child_list<<<=========
7) create a function with name =====>>>>buddyboss_child_list<<<====
function buddyboss_child_list() {
add_action( ‘bp_template_content’, ‘profile_buddyboss_child_loop’ );
bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );
}

The important filters and functions are ..
buddy Press filter ===>>> bp_template_content
buddyPress function to load template =>>> bp_core_load_template

8) Declare and define a new function for content. In the above we have >>profile_buddyboss_child_loop<<< function to fetch data.
/* This is end of the code for above function */
function profile_buddyboss_child_loop() {
$myposts = get_posts( array(
‘posts_per_page’ => -1,
‘author’ => bp_displayed_user_id(),
‘post_type’ => ‘post’
));
if( ! empty($myposts) ) {
foreach($myposts as $post) {
setup_postdata( $post );
if (has_post_thumbnail( $post->ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘sidebar-smallthumbnew’ );
else :
$image[0] = “http://placehold.it/85×60&#8221;;
endif;
echo ‘<li class=”sidebar mostpop post-‘ . $post->ID . ‘”><div id=”postimage”><a href=”‘ . get_permalink($post->ID) . ‘”><img src=”‘ . $image[0] . ‘” /></a></div><div id=”postinfo”><a href=”‘ . get_permalink($post->ID) . ‘”>’ . get_the_title($post->ID) . ‘</a></div></li>’;
}
echo ‘</ul>’;
wp_reset_postdata();
} else { ?>
<div class=”info” id=”message”>
<p><strong><?php bp_displayed_user_fullname(); ?></strong> has No posts.</p>

</div>
<?php }
}
/* This is end of the code for above function */

9) To get no of posts by a author or user, used the below function in the add_filter(‘bp_setup_nav’,”);
function count_user_posts_by_type( $userid, $post_type = ‘post’ ) {
global $wpdb;
$where = get_posts_by_author_sql( $post_type, true, $userid, true);
$count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts $where” );
return apply_filters( ‘get_usernumposts’, $count, $userid );
}

That’s it. By this time your profile page shows the user/author page with their own posts..
Thanks,
Sharma Chelluri

Powered by DW Question & Answer Pro