Title: [Plugin: Posts 2 Posts] How to query connected attachmets
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] How to query connected attachmets

 *  Resolved [Marlon Amâncio](https://wordpress.org/support/users/marlonlamancio/)
 * (@marlonlamancio)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-how-to-query-connected-attachmets/)
 * Please, anyone can help me how to show attachments connected with post.
 * I know that there are specific query functions in WP to achieve similar goal 
   but I want a curated list of related images.
 * I have already registered a connection type with `p2p_register_connection_type`
   hooked in `wp_loaded` and created some connections between posts and some attachments.
 *     ```
       p2p_register_connection_type( array(
       		'name' => 'attachment_to_post',
       		'from' => 'attachment',
       		'to' => 'post',
       		'title' => 'Parceiros relacionados'
       	) );
       ```
   
 * **Now how I query these connections in single post template?**
 * I tried using the function `get_posts()` and also create a new `WP_Query` object
   as shown in basic usage wiki [https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage](https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage).
 * I also tried using `get_connected()` but not returns connected attachments when
   I `print_r()` query object.
 * I’ve read the Wiki, tried to look at the code, I’ve tried so many things that
   it is difficult to list here.
 * Any help will be appreciated.
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  [activefantasies](https://wordpress.org/support/users/activefantasies/)
 * (@activefantasies)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-how-to-query-connected-attachmets/#post-3005639)
 * I’m having this problem too. The setup seems fine and I can link attachments 
   to my CPT in WordPress Admin.
 * I’ve just can’t get the connection data back when I try to use it. I’ve got many
   other connections set up which are working fine, so I gather that it’s something
   to do with connections to/from attachments.
 * Any further info gladly appreciated – and thanks for an incredibly useful plugin.
 *  [Manny Fleurmond](https://wordpress.org/support/users/funkatronic/)
 * (@funkatronic)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-how-to-query-connected-attachmets/#post-3005640)
 *     ```
       $query = WP_Query( array(
           'connected_type' => 'attachment_to_post',
           'connected_items' => $post,
           'post_status' => 'inherit',
           'nopaging' => true,
       ));
       ```
   
 * Secret is to add the post_status as `inherit`. I’m working on an album/gallery
   plugin that uses P2P as the basis and I was banging my head against the wall 
   with this same issue.

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

The topic ‘[Plugin: Posts 2 Posts] How to query connected attachmets’ 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/)

## Tags

 * [attachment](https://wordpress.org/support/topic-tag/attachment/)

 * 2 replies
 * 3 participants
 * Last reply from: [Manny Fleurmond](https://wordpress.org/support/users/funkatronic/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-how-to-query-connected-attachmets/#post-3005640)
 * Status: resolved