Title: [Plugin: Posts 2 Posts] Filtering connections by author
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Filtering connections by author

 *  Resolved [tsahil](https://wordpress.org/support/users/tsahil/)
 * (@tsahil)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/)
 * Hi,
 * I am trying to connect two custom post types to one another. Let’s call them 
   A and B.
 * When someone is adding a post of type A, I want him to be able to connect it 
   to a B post type, but I want to give him a list of B post types that belong only
   to the same author as that who wrote A itself.
 * How can I achieve that?
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766479)
 * You can use the ‘p2p_connectable_args’ filter:
 * [https://github.com/scribu/wp-posts-to-posts/wiki/Admin-box-filters](https://github.com/scribu/wp-posts-to-posts/wiki/Admin-box-filters)
 *  Thread Starter [tsahil](https://wordpress.org/support/users/tsahil/)
 * (@tsahil)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766487)
 * Hi,
 * I tried but it doesn’t work for me:
 *     ```
       function connection_by_author( $args, $ctype, $post_id ) {
       	if ( 'snippet_to_kids' == $ctype->name ) {
       		if (!is_admin())
       			$args['author'] = get_current_user_id();
       	}
   
       	return $args;
       }
       add_filter( 'p2p_connectable_args', 'connection_by_author', 10, 3 );
       ```
   
 * It still shows a “search box” for the posts, and when I ask it to show a list,
   it just shows everyone in the list.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766488)
 * Are you sure it’s running? That `!is_admin()` check looks suspicious.
 *  Thread Starter [tsahil](https://wordpress.org/support/users/tsahil/)
 * (@tsahil)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766489)
 * You are somewhat correct…
    When I remove it, then things change – but now I see
   the wrong post types there – I see the list of posts of the author and not the
   list of kids.
 * And another thing – is there a way to show them there automatically instead of
   having to press on “View all”? I expect the list to be short.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766490)
 * Please paste your ‘snippet_to_kids’ connection type definion in a [http://pastebin.com](http://pastebin.com)
 *  Thread Starter [tsahil](https://wordpress.org/support/users/tsahil/)
 * (@tsahil)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766491)
 * [http://pastebin.com/9U87NFv1](http://pastebin.com/9U87NFv1)
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766492)
 * You should not need to set the post type yourself; it’s set automatically.
 * You might want to check for the direction, though, so that it only affects “snippet”
   or “kid”, not both:
 *     ```
       if ( 'snippet_to_kids' == $ctype->name && 'from' == $ctype->direction )
       ```
   
 * If that doesn’t work, replace ‘from’ with ‘to’.
 *  Thread Starter [tsahil](https://wordpress.org/support/users/tsahil/)
 * (@tsahil)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766502)
 * Didn’t work. Not with ‘from’ and not with ‘to’.
    I still get the full list of
   all kids…
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766503)
 * So, what happens when you use this _exact_ piece of code:
 *     ```
       function connection_by_author( $args, $ctype, $post_id ) {
       	if ( 'snippet_to_kids' == $ctype->name ) {
       		$args['author'] = get_current_user_id();
       	}
   
       	return $args;
       }
       add_filter( 'p2p_connectable_args', 'connection_by_author', 10, 3 );
       ```
   
 * Note that it will only work if the user is logged in.
 *  Thread Starter [tsahil](https://wordpress.org/support/users/tsahil/)
 * (@tsahil)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766504)
 * I am dealing only with logged in users here – this is all done from the backend
   admin panels.
 * When I use it the way you wrote it above, I get the list of snippets instead 
   of the list of kids, and they are those related only to the author himself.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766505)
 * Ok, I set up a similar environment and it works fine for me.
 * Are you sure you don’t have some other code interfering with WP_Query, perhaps
   hooked to ‘pre_get_posts’ or ‘parse_query’?
 *  Thread Starter [tsahil](https://wordpress.org/support/users/tsahil/)
 * (@tsahil)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766506)
 * Yap… that was the issue.
    I had a too-encopassing pre_get_posts filter. Fixed
   that – thanks!
 * One last issue – is there a way to skip the “View all” button and just open up
   the list in advance?
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766507)
 * Yep, it’s already done in the [development version](http://downloads.wordpress.org/plugin/posts-to-posts.zip)(
   1.4-alpha).
 *  Thread Starter [tsahil](https://wordpress.org/support/users/tsahil/)
 * (@tsahil)
 * [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766509)
 * Can’t wait for it to be released 🙂
    I’ll check out the alpha version to see 
   how well it works for me.

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

The topic ‘[Plugin: Posts 2 Posts] Filtering connections by author’ is closed to
new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

 * 14 replies
 * 2 participants
 * Last reply from: [tsahil](https://wordpress.org/support/users/tsahil/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/plugin-posts-2-posts-filtering-connections-by-author/#post-2766509)
 * Status: resolved