Title: [Plugin: Posts 2 Posts] Issue in connection type attachment-&gt;cpt
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Issue in connection type attachment->cpt

 *  [Marlon Amâncio](https://wordpress.org/support/users/marlonlamancio/)
 * (@marlonlamancio)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-issue-in-connection-type-attachment-cpt/)
 * Hello community!
 * I registered my connection type in this way:
 *     ```
       function cria_conexao_variante() {
   
       	if ( !function_exists( 'p2p_register_connection_type' ) )
       		return;
   
       	p2p_register_connection_type( array(
       		'name' => 'parceiro_to_projeto',
       		'from' => 'attachment',
       		'to' => 'projeto',
       		'reciprocal' => true,
       		'title' => 'Parceiros relacionados'
       	) );
       }
   
       add_action( 'wp_loaded', 'cria_conexao_variante' );
       ```
   
 * When editing custom post type `projeto`, show the box for this connection type
   but doesn’t find any attachment when I type title’s attachament in field.
 * What could be this issue?
 * Thanks for any help!
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Thread Starter [Marlon Amâncio](https://wordpress.org/support/users/marlonlamancio/)
 * (@marlonlamancio)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-issue-in-connection-type-attachment-cpt/#post-2982325)
 * Sorry my mistake, I had configured the connection type wrongly, the correct is:
 *     ```
       p2p_register_connection_type( array(
       'name' => 'parceiro_to_projeto',
       'from' => 'attachment',
       'to' => 'projeto'
       ) );
       ```
   
 * After correcting I could create connections =D
 * But now I’m not getting the related attachments when query it in single `projeto`
   template:
 *     ```
       $parceiros = new WP_Query( array(
       'connected_type' => 'parceiro_to_projeto',
       'connected_items' => get_queried_object(),
       ) );
       ```
   
 * I trie this too:
 *     ```
       $parceiros = new WP_Query( array(
       'post_type' => 'attachment',
       'connected_type' => 'parceiro_to_projeto',
       'connected_items' => get_queried_object(),
       'connected_direction' => 'to',
       'nopaging' => true,
       ) );
       ```
   
 * When I `print_r($parceiros)` the object doesn’t hold the related attachments.
 *     ```
       WP_Query Object
       (
           [query_vars] => Array
               (
                   [post_type] => Array
                       (
                           [0] => projeto
                       )
   
                   [connected_items] => stdClass Object
                       (
                           [ID] => 14
                           [post_author] => 2
                           [post_date] => 2012-06-19 18:43:47
                           [post_date_gmt] => 2012-06-19 21:43:47
                           [post_content] => Para confirmar o Show de lançamento do novo CD da Pequena Morte, precisamos arrecadar R$5.000, divididos em 200 ingressos reembolsáveis (R$ 25 cada). Com o show confirmado, a venda de ingressos normais (R$ 40 Inteira e R$20 Meia) começa. Com a venda de 300, os Variantes recebem reembolso integral e assistem ao show de graça.
   
       Temos até o final do dia 25/06, Quinta-Feira, para confirmar a presença do Pequena Morte no Chevrolet Hall.
                           [post_title] => Lançamento do CD da Pequena Morte
                           [post_excerpt] =>
                           [post_status] => publish
                           [comment_status] => open
                           [ping_status] => closed
                           [post_password] =>
                           [post_name] => lancamento-cd-pequena-morte
                           [to_ping] =>
                           [pinged] =>
                           [post_modified] => 2012-08-27 18:27:46
                           [post_modified_gmt] => 2012-08-27 21:27:46
                           [post_content_filtered] =>
                           [post_parent] => 0
                           [guid] => http://variavel5.wpengine.com/?post_type=projeto&p=14
                           [menu_order] => 0
                           [post_type] => projeto
                           [post_mime_type] =>
                           [comment_count] => 0
                           [ancestors] => Array
                               (
                               )
   
                           [filter] => raw
                       )
   
                   [nopaging] => 1
                   [error] =>
                   [m] => 0
                   [p] => 0
                   [post_parent] =>
                   [subpost] =>
                   [subpost_id] =>
                   [attachment] =>
                   [attachment_id] => 0
                   [name] =>
                   [static] =>
                   [pagename] =>
                   [page_id] => 0
                   [second] =>
                   [minute] =>
                   [hour] =>
                   [day] => 0
                   [monthnum] => 0
                   [year] => 0
                   [w] => 0
                   [category_name] =>
                   [tag] =>
                   [cat] =>
                   [tag_id] =>
                   [author_name] =>
                   [feed] =>
                   [tb] =>
                   [paged] => 0
                   [comments_popup] =>
                   [meta_key] =>
                   [meta_value] =>
                   [preview] =>
                   [s] =>
                   [sentence] =>
                   [fields] =>
                   [category__in] => Array
                       (
                       )
   
                   [category__not_in] => Array
                       (
                       )
   
                   [category__and] => Array
                       (
                       )
   
                   [post__in] => Array
                       (
                       )
   
                   [post__not_in] => Array
                       (
                       )
   
                   [tag__in] => Array
                       (
                       )
   
                   [tag__not_in] => Array
                       (
                       )
   
                   [tag__and] => Array
                       (
                       )
   
                   [tag_slug__in] => Array
                       (
                       )
   
                   [tag_slug__and] => Array
                       (
                       )
   
                   [connected_meta] => Array
                       (
                       )
   
                   [suppress_filters] =>
                   [ignore_sticky_posts] => 1
                   [cache_results] =>
                   [update_post_term_cache] => 1
                   [update_post_meta_cache] => 1
                   [posts_per_page] => 10
                   [comments_per_page] => 50
                   [no_found_rows] =>
                   [order] => DESC
               )
   
           [tax_query] => WP_Tax_Query Object
               (
                   [queries] => Array
                       (
                       )
   
                   [relation] => AND
               )
   
           [meta_query] => WP_Meta_Query Object
               (
                   [queries] => Array
                       (
                       )
   
                   [relation] =>
               )
   
           [post_count] => 0
           [current_post] => -1
           [in_the_loop] =>
           [comment_count] => 0
           [current_comment] => -1
           [found_posts] => 0
           [max_num_pages] => 0
           [max_num_comment_pages] => 0
           [is_single] =>
           [is_preview] =>
           [is_page] =>
           [is_archive] => 1
           [is_date] =>
           [is_year] =>
           [is_month] =>
           [is_day] =>
           [is_time] =>
           [is_author] =>
           [is_category] =>
           [is_tag] =>
           [is_tax] =>
           [is_search] =>
           [is_feed] =>
           [is_comment_feed] =>
           [is_trackback] =>
           [is_home] =>
           [is_404] =>
           [is_comments_popup] =>
           [is_paged] =>
           [is_admin] =>
           [is_attachment] =>
           [is_singular] =>
           [is_robots] =>
           [is_posts_page] =>
           [is_post_type_archive] =>
           [query_vars_hash] => ff5b6b55328efdb43f132462317bca7d
           [query_vars_changed] => 1
           [thumbnails_cached] =>
           [query] => Array
               (
                   [post_type] => attachment
                   [connected_type] => parceiro_to_projeto
                   [connected_items] => stdClass Object
                       (
                           [ID] => 14
                           [post_author] => 2
                           [post_date] => 2012-06-19 18:43:47
                           [post_date_gmt] => 2012-06-19 21:43:47
                           [post_content] => Para confirmar o Show de lançamento do novo CD da Pequena Morte, precisamos arrecadar R$5.000, divididos em 200 ingressos reembolsáveis (R$ 25 cada). Com o show confirmado, a venda de ingressos normais (R$ 40 Inteira e R$20 Meia) começa. Com a venda de 300, os Variantes recebem reembolso integral e assistem ao show de graça.
   
       Temos até o final do dia 25/06, Quinta-Feira, para confirmar a presença do Pequena Morte no Chevrolet Hall.
                           [post_title] => Lançamento do CD da Pequena Morte
                           [post_excerpt] =>
                           [post_status] => publish
                           [comment_status] => open
                           [ping_status] => closed
                           [post_password] =>
                           [post_name] => lancamento-cd-pequena-morte
                           [to_ping] =>
                           [pinged] =>
                           [post_modified] => 2012-08-27 18:27:46
                           [post_modified_gmt] => 2012-08-27 21:27:46
                           [post_content_filtered] =>
                           [post_parent] => 0
                           [guid] => http://variavel5.wpengine.com/?post_type=projeto&p=14
                           [menu_order] => 0
                           [post_type] => projeto
                           [post_mime_type] =>
                           [comment_count] => 0
                           [ancestors] => Array
                               (
                               )
   
                           [filter] => raw
                       )
   
                   [connected_direction] => to
                   [nopaging] => 1
               )
   
           [_p2p_query] => P2P_Query Object
               (
                   [ctypes:protected] => Array
                       (
                           [0] => P2P_Directed_Connection_Type Object
                               (
                                   [ctype:protected] => P2P_Connection_Type Object
                                       (
                                           [indeterminate] =>
                                           [object] => Array
                                               (
                                                   [from] => post
                                                   [to] => attachment
                                               )
   
                                           [side] => Array
                                               (
                                                   [from] => P2P_Side_Post Object
                                                       (
                                                           [item_type:protected] => P2P_Item_Post
                                                           [query_vars] => Array
                                                               (
                                                                   [post_type] => Array
                                                                       (
                                                                           [0] => projeto
                                                                       )
   
                                                               )
   
                                                       )
   
                                                   [to] => P2P_Side_Attachment Object
                                                       (
                                                           [item_type:protected] => P2P_Item_Attachment
                                                           [query_vars] => Array
                                                               (
                                                                   [post_type] => Array
                                                                       (
                                                                           [0] => attachment
                                                                       )
   
                                                               )
   
                                                       )
   
                                               )
   
                                           [cardinality] => Array
                                               (
                                                   [from] => many
                                                   [to] => many
                                               )
   
                                           [title] => Array
                                               (
                                                   [from] => Parceiros relacionados
                                                   [to] => Parceiros relacionados
                                               )
   
                                           [labels] => Array
                                               (
                                                   [from] => stdClass Object
                                                       (
                                                           [name] => Projetos
                                                           [singular_name] => Projeto
                                                           [add_new] => Inserir novo
                                                           [add_new_item] => Inserir novo projeto
                                                           [edit_item] => Editar projeto
                                                           [new_item] => Novo projeto
                                                           [view_item] => Ver projeto
                                                           [search_items] => Buscar projetos
                                                           [not_found] => Nenhum projeto encontrado
                                                           [not_found_in_trash] => Nenhum projeto encontrado na Lixeira
                                                           [parent_item_colon] =>
                                                           [all_items] => Projetos
                                                           [menu_name] => Projetos
                                                           [edit] => Editar
                                                           [view] => Ver projeto
                                                           [parent] => Projeto Pai
                                                           [name_admin_bar] => Projeto
                                                           [create] => Create connections
                                                           [0] =>
                                                       )
   
                                                   [to] => stdClass Object
                                                       (
                                                           [name] => Mídia
                                                           [singular_name] => Mídia
                                                           [add_new] => Adicionar Novo
                                                           [add_new_item] => Adicionar novo post
                                                           [edit_item] => Editar Mídia
                                                           [new_item] => Novo Post
                                                           [view_item] => Ver Post
                                                           [search_items] => Pesquisar posts
                                                           [not_found] => Nenhum post encontrado.
                                                           [not_found_in_trash] => Nenhum post encontrado na Lixeira.
                                                           [parent_item_colon] =>
                                                           [all_items] => Mídia
                                                           [menu_name] => Mídia
                                                           [name_admin_bar] => Mídia
                                                           [create] => Create connections
                                                           [0] =>
                                                       )
   
                                               )
   
                                           [fields] => Array
                                               (
                                               )
   
                                           [name] => parceiro_to_projeto
                                           [data] => Array
                                               (
                                               )
   
                                           [duplicate_connections] =>
                                           [self_connections] => 1
                                           [sortable] =>
                                           [reciprocal] =>
                                       )
   
                                   [direction:protected] => to
                               )
   
                       )
   
                   [items:protected] => stdClass Object
                       (
                           [ID] => 14
                           [post_author] => 2
                           [post_date] => 2012-06-19 18:43:47
                           [post_date_gmt] => 2012-06-19 21:43:47
                           [post_content] => Para confirmar o Show de lançamento do novo CD da Pequena Morte, precisamos arrecadar R$5.000, divididos em 200 ingressos reembolsáveis (R$ 25 cada). Com o show confirmado, a venda de ingressos normais (R$ 40 Inteira e R$20 Meia) começa. Com a venda de 300, os Variantes recebem reembolso integral e assistem ao show de graça.
   
       Temos até o final do dia 25/06, Quinta-Feira, para confirmar a presença do Pequena Morte no Chevrolet Hall.
                           [post_title] => Lançamento do CD da Pequena Morte
                           [post_excerpt] =>
                           [post_status] => publish
                           [comment_status] => open
                           [ping_status] => closed
                           [post_password] =>
                           [post_name] => lancamento-cd-pequena-morte
                           [to_ping] =>
                           [pinged] =>
                           [post_modified] => 2012-08-27 18:27:46
                           [post_modified_gmt] => 2012-08-27 21:27:46
                           [post_content_filtered] =>
                           [post_parent] => 0
                           [guid] => http://variavel5.wpengine.com/?post_type=projeto&p=14
                           [menu_order] => 0
                           [post_type] => projeto
                           [post_mime_type] =>
                           [comment_count] => 0
                           [ancestors] => Array
                               (
                               )
   
                           [filter] => raw
                       )
   
                   [query:protected] => Array
                       (
                       )
   
                   [meta:protected] => Array
                       (
                       )
   
                   [orderby:protected] =>
                   [order:protected] =>
                   [order_num:protected] =>
               )
   
           [request] => SELECT   wp_posts.*, wp_p2p.* FROM wp_posts  INNER JOIN wp_p2p WHERE 1=1  AND wp_posts.post_type IN ('projeto') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 2 AND wp_posts.post_status = 'private') AND (wp_p2p.p2p_type = 'parceiro_to_projeto' AND wp_posts.ID = wp_p2p.p2p_from AND wp_p2p.p2p_to IN (SELECT   wp_posts.ID FROM wp_posts  WHERE 1=1  AND wp_posts.ID IN (14) AND wp_posts.post_type IN ('attachment') AND (wp_posts.post_status = 'inherit')  ORDER BY wp_posts.post_date DESC ))  ORDER BY wp_posts.post_date DESC
           [posts] => Array
               (
               )
   
       )
       ```
   
 * I know that there are specific functions in WP to achieve similar goal but I 
   want a curated list of related images.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-issue-in-connection-type-attachment-cpt/#post-2982345)
 * Try setting the post status:
 *     ```
       $parceiros = new WP_Query( array(
         'post_type' => 'attachment',
         'post_status' => 'inherit',
          ...
       ```
   
 *  Thread Starter [Marlon Amâncio](https://wordpress.org/support/users/marlonlamancio/)
 * (@marlonlamancio)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-issue-in-connection-type-attachment-cpt/#post-2982349)
 * Did not worked, any other thoughts?
 * Thanks for you attention Scribu.
 *  Thread Starter [Marlon Amâncio](https://wordpress.org/support/users/marlonlamancio/)
 * (@marlonlamancio)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-issue-in-connection-type-attachment-cpt/#post-2982383)
 * Scribu,
 * I think I noticed something, within `WP_Query` object the value of key `post_type`
   in `query_vars` array is `projeto`, should not be `attachment` in this case?
 * Thank you!

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

The topic ‘[Plugin: Posts 2 Posts] Issue in connection type attachment->cpt’ 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/)

 * 4 replies
 * 2 participants
 * Last reply from: [Marlon Amâncio](https://wordpress.org/support/users/marlonlamancio/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-issue-in-connection-type-attachment-cpt/#post-2982383)
 * Status: not resolved