wp-posts-to-posts icon indicating copy to clipboard operation
wp-posts-to-posts copied to clipboard

get_adjacent_items: More than one connected parents found

Open imjjss opened this issue 10 years ago • 3 comments

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?

imjjss avatar Apr 23 '14 12:04 imjjss

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

Parent A has:

  • Child A
  • Child B
  • Child C

Parent B has:

  • Child A
  • Child B
  • Child C
  • Child D

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

Defrothew avatar Apr 23 '14 14:04 Defrothew

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

imjjss avatar Apr 23 '14 15:04 imjjss

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

JiveDig avatar Mar 25 '16 17:03 JiveDig