scribu / wp-posts-to-posts

Efficient many-to-many connections between posts, pages, custom post types, users.
http://wordpress.org/plugins/posts-to-posts/
974 stars 260 forks source link

Missing P2P properties in WP_Post Object #435

Open Defrothew opened 10 years ago

Defrothew commented 10 years ago

Updated: Or is this how it works?

There is a missing P2P properties in WP_Post Object for parent, next and previous item connected when using a filter 'post_type_link' but other connected items have the P2P properties on the said filter.

1st item:

WP_Post Object
(
    [ID] => 189
    [post_author] => 1
    [post_date] => 2014-04-23 12:41:27
    [post_date_gmt] => 2014-04-23 12:41:27
    [post_content] => 
    [post_title] => Game Of Thrones – Season 2 – Episode 2
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
    [post_password] => 
    [post_name] => game-of-thrones-season-2-episode-2
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2014-04-23 12:41:27
    [post_modified_gmt] => 2014-04-23 12:41:27
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://localhost/apps/webtube/?post_type=video&p=189
    [menu_order] => 0
    [post_type] => video
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
    [p2p_id] => 168
    [p2p_from] => 189
    [p2p_to] => 187
    [p2p_type] => season
)

2nd item: (Previous - Missing P2P properties)

WP_Post Object
(
    [ID] => 190
    [post_author] => 1
    [post_date] => 2014-04-23 12:41:27
    [post_date_gmt] => 2014-04-23 12:41:27
    [post_content] => 
    [post_title] => Game Of Thrones – Season 2 – Episode 3
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
    [post_password] => 
    [post_name] => game-of-thrones-season-2-episode-3
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2014-04-23 12:41:27
    [post_modified_gmt] => 2014-04-23 12:41:27
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://localhost/apps/webtube/?post_type=video&p=190
    [menu_order] => 0
    [post_type] => video
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
)

3rd item: (Parent - Currently in this single post query - Missing P2P properties)

WP_Post Object
(
    [ID] => 194
    [post_author] => 1
    [post_date] => 2014-04-23 13:10:31
    [post_date_gmt] => 2014-04-23 13:10:31
    [post_content] => 
    [post_title] => Game Of Thrones – Season 2 – Episode 4
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
    [post_password] => 
    [post_name] => game-of-thrones-season-2-episode-4
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2014-04-23 13:10:31
    [post_modified_gmt] => 2014-04-23 13:10:31
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://localhost/apps/webtube/?post_type=video&p=194
    [menu_order] => 0
    [post_type] => video
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
)

4th item: (Next - Missing P2P properties)

WP_Post Object
(
    [ID] => 195
    [post_author] => 1
    [post_date] => 2014-04-23 13:10:31
    [post_date_gmt] => 2014-04-23 13:10:31
    [post_content] => 
    [post_title] => Game Of Thrones – Season 2 – Episode 5
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
    [post_password] => 
    [post_name] => game-of-thrones-season-2-episode-5
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2014-04-23 13:10:31
    [post_modified_gmt] => 2014-04-23 13:10:31
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://localhost/apps/webtube/?post_type=video&p=195
    [menu_order] => 0
    [post_type] => video
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
)

I've noticed that when going to every connected item, the missing P2P type in Post object behaves on this format: Previous, Parent and Next items.

Example No. 1: 1st item | 2nd item - Previous (Missing) | 3rd item - Parent (Missing) | 4th item - Next (Missing)

Example No. 2: 1st item - Previous (Missing) | 2nd item - Parent (Missing) | 3rd item - Next (Missing) | 4th item

To recreate this scenerio:

// Query | from: 'season' post type, to: 'video'
p2p_type( 'season' )->get_related( get_queried_object_id(), $args );

// Existing filter for custom post type permalink
function __post_type_link( $permalink, $post, $leavename, $sample ) {
   print_r($post);
   return $permalink;
}
add_filter( 'post_type_link', '__post_type_link', 10, 4 );

Using the query code snippet above and you are on single 'video' page.

I'm still on the verge of looking at the core files which is responsible for this.

Thanks

Defrothew commented 10 years ago

Anyone encountering this problem in the future, my workaround for this is, I added global $post to the function attached to "post_type_link" filter.