Plugin Author
scribu
(@scribu)
Ok, and how does the ‘posts_to_posts’ connection type look like?
p2p_register_connection_type( array(
'name' => 'posts_to_posts',
'from' => 'post',
'to' => 'post',
'reciprocal' => true,
'prevent_duplicates' => false
) );
I actually do
`$connected = new WP_Query( array(
‘post_type’ => array(‘post’,’vessel’),
‘cat’ => ‘-933’,
‘posts_per_page’ => ‘5’,
‘orderby’ => ‘rand’,
‘connected_type’ => array(‘posts_to_posts’,’posts_to_vessels’),
‘connected_items’ => get_queried_object_id(),
‘nopaging’ => true
) ); `
and my vessel connection is
`p2p_register_connection_type( array(
‘name’ => ‘posts_to_vessels’,
‘from’ => ‘post’,
‘to’ => ‘vessel’,
‘reciprocal’ => true,
‘prevent_duplicates’ => false
) ); `
but even trying to strip it down, getting same error
Plugin Author
scribu
(@scribu)
Also, what do you get when you do var_dump( get_queried_object() ); ?
object(stdClass)#717 (25) { [“ID”]=> int(1356) [“post_author”]=> string(1) “3” [“post_date”]=> string(19) “2011-05-26 09:32:40” [“post_date_gmt”]=> string(19) “2011-05-26 09:32:40” [“post_content”]=> string(2579) ” [caption id="attachment_9993" align="alignleft" width="240" caption="Title-II"][“post_title”]=> string(10) “Title II” [“post_excerpt”]=> string(0) “” [“post_status”]=> string(7) “publish” [“comment_status”]=> string(4) “open” [“ping_status”]=> string(6) “closed” [“post_password”]=> string(0) “” [“post_name”]=> string(10) “Title-ii” [“to_ping”]=> string(0) “” [“pinged”]=> string(0) “” [“post_modified”]=> string(19) “2011-11-30 13:44:37” [“post_modified_gmt”]=> string(19) “2011-11-30 13:44:37” [“post_content_filtered”]=> string(0) “” [“post_parent”]=> int(0) [“guid”]=> string(77) “http://URL&p=1356” [“menu_order”]=> int(0) [“post_type”]=> string(6) “vessel” [“post_mime_type”]=> string(0) “” [“comment_count”]=> string(1) “0” [“ancestors”]=> array(0) { } [“filter”]=> string(3) “raw” }
Plugin Author
scribu
(@scribu)
Thanks, I was able to reproduce the error. Will have a fix soon.
Thx.
Can you also look at the posts_per_page, as it doesnt seem to work, but was before.
I am trying, as the code above to display only 5 related, at random.
But getting the full list.
Sorry for the trouble
Plugin Author
scribu
(@scribu)
It doesn’t work because you also pass 'nopaging' => true.
Plugin Author
scribu
(@scribu)
The SQL error should be fixed in the development version (1.2-alpha2).
nopaging = silly me.
will dig into alpha2 in the morning.
thx again
grr…
ok it’s working some places, but not in other…
I am listing a post type, fine, and for each, inside the loop, I need to find if other articles are connected to the one in the loop.
So I execute the query below. If an article connected if found, i display an icon (ok)…
$the_query = new WP_Query( array(
'post_type' => array('post', 'destination'),
'connected_type' => array('posts_to_posts','posts_to_destinations'),
'connected_items' => get_queried_object_id()
) );
var_dump(get_queried_object_id());
if($the_query->have_posts()) :
echo "ok";
else:
echo "none";
endif;
wp_reset_postdata();
The dump, returns, int(0).
if I try to use $post->ID, not working, but $post->ID is correct in the loop, ie returns the proper id for the current record in the loop.
Ok, I made 2 mistake in my query above.
1/ Inside the loop I should use
https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop
2/ I was trying to find a connection that didnt exist.
Now, I actually ant to use this to only display an icon if a connection exist, and if try to do
$connectedarticle = p2p_type('posts_to_destinations' )->get_connected( $post->ID );
if($connectedarticle){
echo display_article_icon($post->ID);
}
it will display the icon, but on all item in loop and not only the one which have the connection
if using
p2p_list_posts( $connectedarticle );
it will only display articles where they are connected…
Can i do,
if(p2p_list_posts){
echo display_article_icon($post->ID);
}
?
ok, what I needed to do was
Before my While…
p2p_type( 'posts_to_destinations' )->each_connected( $wp_query, array(), 'articles' );
and in my loop
if($post->articles){
//do my thing
}