• Resolved Marlon Amâncio

    (@marlonlamancio)


    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.

    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/

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    $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.