scribu / wp-posts-to-posts

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

get_adjacent_items: More than one connected parents found #434

Open imjjss opened 10 years ago

imjjss commented 10 years ago

I registered a many-to-many connection type, from a custom-post-type to itself, sortable=true. Then, I added 3 connections to one post of this cpt. When I tried $items = p2p_type('steps')->get_adjacent_items($id), I got a warning: "More than one connected parents found". var_dump($items) shows the result has 3 elements-- $items['parent'] is the first connection which I think it should be the first child. $items['previous']' and$items['next']are bothfalse`. Where did I go wrong?

Defrothew commented 10 years ago

Well, that means that you have multiple parent items connected to the same children items.

Parent A has:

Parent B has:

The tendency is that the p2p_type( $p2p_type )->get_adjacent_items( $object_id ) will be confused on which parent items to use as a basis. (Where $object_id is a child item)

If you are just utilizing your parent item once then just set your cardinality to 'one-to-many' or 'many-to-one' to avoid multiple connections to your parent item and avoiding the "More than one connected parents found." E_USER_WARNING. (Disclaimer: Please test this out before pushing this changes to your live application.)

Thanks, Defrothew

imjjss commented 10 years ago

@Defrothew , I just cleaned my testing site. The 3 connections are the only records in the wp_p2p table. So, I guess the trouble may come from the fact that the connection type is from the cpt to the cpt itself.

JiveDig commented 8 years ago

Way later, but same issue here. @imjjss do you remember how you resolved this?