Cameron Brown
asked 8 years ago

I want a user to see their listings (and their listings only) on their login landing page, is there a shortcode for this?
If not I would be willing to implement a PHP solution.

5 Answers
Cameron Brown
answered 8 years ago

This is a plug-and-play solution modified from @BigHug ‘s solution 

 <ul>
<?php
$author_id = get_current_user_id(); // Specify the user ID whole questions will be shown
$args = array(
    'posts_per_page' => 5, //Number of Questions
    'post_type' => 'dwqa-question', //Get the questions only
    'post_author' => $author_id, // the ID of user
        'post_status' => 'publish'
    );
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
       <?php if ($post->post_author==$author_id): ?>
       <li>
            <a href="<?php echo $post->guid; ?>"><?php echo $post->post_title; ?></a>
            <p><?php echo $post->post_content; ?></p>
            <span><?php echo $post->comment_count; ?> comments</span>
       </li>
        <?php endif; ?>
    <?php endforeach; ?>
<?php wp_reset_postdata();?>
</ul>
Guru
replied 8 years ago

Glad that you have found the solution 🙂

well wisher
answered 8 years ago

you can install buddypress and then set the “questions tab” as the default landing tab(default is set to activity tab) when a user logs in, there are a whole lot of plugin out there which can do this for you !!!
Only a plugin to redirect user to custom link after login you specify in settings should work for you try theme my login plugin and redirect each user to the qustions tab link after login !!! 

Cameron Brown
replied 8 years ago

I'm afraid you misunderstood the question. I already have the user redirected to the page I want, on that page I want to display their questions. I don't want another plugin to make this work, as that may conflict with the other plugins that already function in this way.
I either want [dwqa-manage-questions] or dwqa_get_questions($cur_user);

well wisher
replied 8 years ago

Oh now i got it i think you just want to create a section in your predefined page which will include a list of questions asked by the logged in user along with you other content using shortcodes well in that case i think there are no shortcodes available to do that task for you currently but if you only want to display the list of questions asked by the logged in user check my comment in the answer provided by guru

well wisher
answered 8 years ago

Ok this is the link to your profile’s question tab on the design wall website http://designwall.com/profile/calibre/questions/ is that what you want to do on your default page (displaying only the questions you have asked)?

Cameron Brown
replied 8 years ago

That’s what I’m looking for, is this only available through buddy press? I’m working on a project with limited scope and I would sooner leave this boxed un-ticked than spend time getting my head around another plugin

Guru
replied 8 years ago

You can work with other plugins such as bbpress too, but not having a plugin would mean alot of work, which would require a dedicated coder.

Guru
answered 8 years ago

Hi all I guess what you are looking for is for the logged-in user to only see the question they have posted and the related answers.
If this is the case, I am afraid this is not available by default. It requires modification of the code. This is a special case as in normal circumstances you won’t require this functionality.
 

well wisher
replied 8 years ago

Yaa thats what i am trying to say the designwall team has added a bp-custom.php file in wordpress along with the buddypress installed the code in the bp-custom.php is to create a new custom tab for every profile showing only the questions asked by him/her like if you click on this link http://cmspioneer.com/designwall/profile/calibre/questions/ it will only show the questions asked by Cameron Brown himself and thats what he need i suppose ,did i missed something ?

Cameron Brown
replied 8 years ago

I should repeat I’m willing to implement a PHP solution!

Guru
replied 8 years ago

sorry I have lost you there!

BigHug
answered 8 years ago

Hey guys,
@calibre
If you want to use php to get all questions of a user, you can do it by using the  get_posts() function that was supported by wordpress ( Document ) . I added a sample here:

 <ul>
<?php

$author_id = 1; // Specify the user ID whole questions will be shown $args = array(
'posts_per_page' => 5, //Number of Questions
'post_type' => 'dwqa-question', //Get the questions only
'post_author' => $author_id, // the ID of user
'post_status' => 'publish'
); $myposts = get_posts( $args ); foreach ( $myposts as $post ) : setup_postdata( $post ); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endforeach; wp_reset_postdata();?> </ul>

Hope this helps!

Cameron Brown
replied 8 years ago

Thankyou! That’s what I was looking for.

well wisher
replied 8 years ago

@bighug will it not be showing the questions for only a particular user id that we would have specified manually which is user id 1 here in the above case ?

BigHug
replied 8 years ago

i just show a sample code here, you can convert this code into a function or a shortcode where the $author_id value can be assigned through shortcode atrribute or function variable.
@calibre solved it by himself, he got the ID of current user through function get_current_user_id(). His answer was marked as the best, you can view it on top of the answer list.

well wisher
replied 8 years ago

yaa i saw that thanks a lot for the example solution @bighug was just making sure that @calibre and others here wont get confused over it but now that the universal code has been added by @calibre its great thanks once again.

Yan
answered 7 years ago

Hi Cameron,
Did you manage to customize the profile page without buddypress?
Thanks!

DominicStaff
answered 7 years ago

Apologies for the delay in replying. At the moment, you only possible use the Buddypress plugin to create a profile page.
Regards,

Powered by DW Question & Answer Pro