count connections not working
-
In an earlier thread, scribu posted this for counting connections:
$connected = new WP_Query( array( 'post_type' => 'page', 'connected_from' => $post->ID ) ); echo $connected->found_posts;
I’ve been trying to use it in my single.php and it always returns zero. I have code which properly displays connections to other post types, so I know they exist, and are working. But the above snippet doesn’t detect them.
My site uses custom post types ‘toys’, ‘stores’, ‘builders’
I have a post of type ‘toys’ which has properly displayed connections to ‘stores’ and another connection to a ‘builders’ post.But these code snippets all produce an answer of zero:
$connected = new WP_Query( array( 'post_type' => 'stores', 'connected_from' => $post->ID ) ); echo $connected->found_posts; $connected = new WP_Query( array( 'post_type' => 'builders', 'connected_from' => $post->ID ) ); echo $connected->found_posts; $connected = new WP_Query( array( 'post_type' => 'toys', 'connected_from' => $post->ID ) ); echo $connected->found_posts;
I’ve tried replacing $post->ID with get_queried_object() too, as well as ‘connected_from’ to ‘connected_to’ – I really have no idea what I’m doing!
What I really need is to be able to tell if a given post has more than 0 connections of ANY type.
- The topic ‘count connections not working’ is closed to new replies.