Plugin Author
scribu
(@scribu)
With the development version (1.3-alpha3), you can just pass the array of post objects to WP_Query or to get_posts():
$connected = get_posts( array(
'connected_items' => $zone_posts,
'connected_type' => array( 'CONNECTION_TYPE1', 'CONNECTION_TYPE2', ... ),
'connected_direction' => 'any',
'post_type' => 'any',
'suppress_filters' => false
) );
This should return all the connected posts involved.
Thanks you so much! That was exactly what I was trying to achieve.
By the way, can I use $connected on p2p_list_posts?
Thanks, again.
EDIT: Hmm just tried it – obviously, if I use p2p_list_posts($connected)
on the loop I get the same list of post for every post on the loop :\
Plugin Author
scribu
(@scribu)
I just moved the list splitting logic from each_connected()
into a standalone function in the development version. Usage example:
$connected = get_posts( array(
'connected_items' => $zone_posts,
'connected_type' => array( 'CONNECTION_TYPE1', 'CONNECTION_TYPE2', ... ),
'connected_direction' => 'any',
'post_type' => 'any',
'suppress_filters' => false
) );
p2p_distribute_connected( $zone_posts, $connected, 'connected' );
foreach ( $zone_posts as $post ) {
setup_postdata($post);
the_title();
p2p_list_posts( $post->connected );
...
}
Yay, thanks again! Works as expected. *looks for donate button on your site* 🙂
Another quick question: if I set 'connected_type' => array( 'posts_to_posts', 'posts_to_galleries', 'posts_to_videos')
it only lists posts_to_galleries and _to_videos – however, if I only set 'connected_type' => array( 'posts_to_posts')
it does lists the connections from that type. Could this be a bug or expected behavior, since it’s an indeterminate connection type?
Thank you so much again.
EDIT: Actually, it seems the problem occurs everytime I set more than two connection types on that array.
Plugin Author
scribu
(@scribu)
I forgot one thing about the get_posts() call: 'nopaging' => true
. See if that helps.
*looks for donate button on your site*
If you can’t find it, it means I suck at design. 🙂
Ah, that was it!
By the way, how can that new function still be used in a normal WP Query? (I have some pages on the project that don’t rely on Zoninator).
Thanks! And just kicking, the button is very easily found 🙂
Plugin Author
scribu
(@scribu)
It just takes two arrays of posts:
p2p_distribute_connected( $my_query->posts, $connected, 'connected' );
Hmm I’m using the global $wp_query
like this:
$connected = new WP_Query ( array(
'connected_items' => $wp_query->posts,
'connected_type' => array( 'posts_to_posts', 'posts_to_fotogalerias', 'posts_to_videos'),
'connected_direction' => 'any',
'post_type' => 'any',
'nopaging' => true,
'suppress_filters' => false
) );
p2p_distribute_connected( $wp_query->posts, $connected, 'connected' );
…but it only lists one connection for one connection type (even with nopaging
set) and I get some warnings (Notice: Trying to get property of non-object in [...]/wp-content/plugins/posts-to-posts/core/api.php on line 339
).
Thanks!
Plugin Author
scribu
(@scribu)
p2p_distribute_connected( $wp_query->posts, $connected->posts, 'connected' );
Ah, brilliant.
Also, silly me making a new WP_Query
for $connected
– it works if I do it with get_posts.
Thanks again for all the help, donation on its way.