Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 119618

wp-MeMeMe on "[Plugin: Posts 2 Posts] count connections not working"

$
0
0

That does work! Thanks.

I have to repeat this several times in the template for each connection, count the number and if the total is greater than 0, draw a styling block to contain the connection details.

So, I tried to create a function in my core functionality plugin, like this:

function swg_count_connections_single($post_id,$connection_type){
	$connected = new WP_Query( array(
			'connected_type'  => $connection_type,
			'connected_items' => $post->ID,
	) );
	wp_reset_postdata(); // is this needed?
	return $connected->found_posts;
}

and called it in the template (for testing purposes) like this:

$swg_count_of_connections =  swg_count_connections_single($post->ID,'builders_to_toys');
echo $swg_count_of_connections;

This doesn't work, it always returns zero. What am I missing?


Viewing all articles
Browse latest Browse all 119618

Trending Articles