Skip to:
Content
Pages
Categories
Search
Top
Bottom

Private Blogs


  • raghav2417
    Participant

    @raghav2417

    Hi
    I need help with my Buddypress website, My website requires a functionality where a user can post the blog using the frontend. This I have achieved, However I want when a user clicks on view blogs, they should be able to see only the blogs written by themselves and any blog of which the current user is not an author should not be visible to the user.

    I am struggling with this right now and need help.
    All I want is the blogs to be private at frontend.

    Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)

  • Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    Is it a custom template where blogs are listing or default WordPress blog page?

    Thanks


    raghav2417
    Participant

    @raghav2417

    Hi Its a buddypress members dashboard, Where in one of the tabs I have added a page that allows members to write a post, Now these posts are saved as private and I want only the member writing that post to be able to view it, no other members of the website should be able to view it, However when we click on the view post button, It shows all the posts even though they are private but still it shows.
    I want the member clicking on view your post should see only posts written by himself/herself.
    Below is a link to the video describing the issue.
    https://drive.google.com/file/d/1BUNazNHAC7b_3yvXs79GmLHSwSG3uXJU/view?usp=sharing

    Thanks alot


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    Please put this snippet in child theme’s functions.php file:

    function ps_private_posts( $query ) {
    	if(is_user_logged_in()){
    	    if ( $query->is_archive() && $query->is_main_query() ) {
    	        $query->set( 'author', get_current_user_id());
    	    }
    	}
    }
    add_action( 'pre_get_posts', 'ps_private_posts' );

    Hopefully, it will help you.

    Thanks


    raghav2417
    Participant

    @raghav2417

    Hi this didnt work, It still shows the posts from other users,
    currently my button URL which takes me to the posts is website.com/category/categoryname If you can help me with the right URL then it might solve the problem, Something like website.com/author_posts
    such that it shows posts only by the current user.


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    If you can change the button link then certainly this should help:

    <a href="<?php echo get_author_posts_url( get_current_user_id()); ?>">See Posts</a>

    Thanks


    raghav2417
    Participant

    @raghav2417

    Hi thanks for all the help
    I wrote this code to Functions.php and this did the trick

    function my_vc_shortcode( $atts ) {

    global $user_ID;
    $user_info = get_userdata($user_ID);
    $current_link = get_author_posts_url($user_id,$user_info->user_nicename);
    echo ‘<center>View All Posts</center>’;
    }
    add_shortcode( ‘my_vc_php_output’, ‘my_vc_shortcode’);

    Thanks again


    Prashant Singh
    Participant

    @prashantvatsh

    Perfect 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar