• Resolved sagar_mehta

    (@sagar_mehta)


    As the title says, what I’m trying to achieve is simply this:

    I have a page called ‘Ask A Question’ which is my posts page. So, whenever a contributor adds a post, it shows up here. Now, what I want to do is that when the contributor logs in, he should be able to see only his own posts on this page (the front end).

    I looked around the forum and found a solution to hide posts of other contributors in the backend by adding a function in the functions.php (there’s also a plugin for it here)

    But how to do it on the front end is totally beyond me. ??

    Sagar

Viewing 2 replies - 1 through 2 (of 2 total)
  • In your Page Template could use something like:

    <?php
    //if a certain page, then display posts authored by the logged in user
    $page_title = 'Contributors Page';
    if ( is_user_logged_in()  && is_page($page_title) ) {
      global $current_user;
      get_currentuserinfo();
      echo 'User ID: ' . $current_user->ID . "\n";
      $args=array(
        'author' => $current_user->ID,
        'post_type' => 'post',
        'post_status' => 'publish, private',
        'posts_per_page' => -1,
        'caller_get_posts'=> 1
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo 'Your Posts';
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php
        endwhile;
      }
      wp_reset_query();  // Restore global post data stomped by the_post().
    }
    ?>

    Thread Starter sagar_mehta

    (@sagar_mehta)

    Thanks a lot for that code Michael. Works really well!

    For anyone who’s trying to achieve the above, put the code in your page template.

    Then, whenever any post is made by a contributor and is set to ‘Private’, only that contributor will see the post. To all others, it will be hidden.

    Thanks again!

    Regards,
    Sagar

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Let contributors see own posts on Front End’ is closed to new replies.