scribu/wp-posts-to-posts — Issue #105: Relating a custom post type to an attachment not working on front end?
Author: benhuson
Created: 2012-01-25 19:37:38+00:00
State: open

I can associate a custom post type with attachment which works fine in the admin:

function my_p2p_connection_types() {
if ( !function_exists( 'p2p_register_connection_type' ) )
return;
p2p_register_connection_type( array(
'name' => 'wpsc_product_attachment',
'from' => 'product',
'to' => 'attachment'
) );
}
add_action( 'wp_loaded', 'my_p2p_connection_types' );

But the front end methods you provide do not output anything.
If I print_r() the query...

$connected = p2p_type( 'wpsc_product_attachment' )->get_connected( $post->id );
print_r($connected);

The query SQL is:
SELECT SQL_CALC_FOUND_ROWS tls_posts.*, tls_p2p.* FROM tls_posts INNER JOIN tls_p2p WHERE 1=1 AND tls_posts.post_type IN ('attachment') AND (tls_posts.post_status = 'publish' OR tls_posts.post_author = 6 AND tls_posts.post_status = 'private') AND tls_p2p.p2p_type = 'wpsc_product_attachment' AND tls_posts.ID = tls_p2p.p2p_to AND tls_p2p.p2p_from IN (5578) ORDER BY tls_posts.post_date DESC LIMIT 0, 5

But for media it needs to check if tls_posts.post_status = 'inherit'

Is there a filter of parameter I can add to change that or does it require a change to the core plugin to automatically change it for attachments?

Many thanks

- Ben