• Resolved David Wang

    (@blogjunkie)


    I’m using Posts 2 Users to associate one or more users to a post and a custom post type called ‘proposal’.

    Now on the index and archive pages, I only want to display the posts associated to that user i.e. the user is not able to see a post if it has not been associated with him.

    I’ve had a look through the documentation but I don’t see anything that shows me how to filter the loop according to the currently logged in user. Can Posts 2 Posts do what I want?

    Thanks

    http://wordpress.org/extend/plugins/posts-to-posts/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author scribu

    (@scribu)

    Yep, you can use the ‘parse_query’ action:

    function filter_viewable_posts( $wp_query ) {
      if ( ! $wp_query->is_main_query() )
        return;
    
      $wp_query->set( 'connected_type', 'YOUR_CONNECTION_TYPE' );
      $wp_query->set( 'connected_items', get_current_user_id() );
    }
    add_action( 'parse_query', 'filter_viewable_posts' );
    Thread Starter David Wang

    (@blogjunkie)

    Thanks scribu, that gives me something to work on 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Posts 2 Posts] Display posts only to associated users’ is closed to new replies.