<?php
global $post;
$args = array(
'post_type' => 'something',
'posts_per_page' => -1,
);
MB_Relationships_API::each_connected(
array(
'id' => 'users_to_something',
'from' => $test_query->posts, // tried both to/from
'property' => 'clients',
)
);
$test_query = new WP_Query( $args );
while ( $test_query->have_posts() ) :
setup_postdata( $post );
$test_query->the_post();
var_dump($post); // the relationship parameter "clients" has nothing inside
// Display connected pages (not working because there is no relationships found by each_connected)
foreach ( $post->clients as $p ) :
// More core here...
endforeach;
// Get individually(Working properly.).
$users = get_users(
array(
'relationship' => array(
'id' => 'users_to_something',
'to' => get_the_ID(),
),
)
);
foreach ( $users as $user ) {
echo $user->display_name;
}
endwhile;
The “each_connected” function seems not working as expected but query separately using “get_user” seems to working.
In this code, is there anything missed in the “each_connected”?
This works, but I can’t get pagination to work:
p2p_type( 'post_to_project' )->each_connected( $wp_query, array(), 'post' );
while ($wp_query->have_posts() ) : $wp_query->the_post();
p2p_type( 'post_to_author' )->each_connected( $post->post, array(), 'connected' ); // connected contains author_cpt's
foreach ( $post->post as $post ) : setup_postdata( $post );
get_template_part( 'content', 'excerpt' );
endforeach;
endwhile;
if (function_exists('wp_pagenavi'))
wp_pagenavi( array( 'query' => $wp_query) );
and this works with pagination, but the author doesn’t show.
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$connected_posts = new WP_Query( array(
'connected_type' => 'post_to_project',
'connected_items' => get_queried_object(),
'posts_per_page' => 6,
'paged' => $paged
) );
// Display connected posts
if ( $connected_posts->have_posts() ) :
while ( $connected_posts->have_posts() ) : $connected_posts->the_post();
get_template_part( 'content', 'excerpt' );
endwhile;
if (function_exists('wp_pagenavi'))
wp_pagenavi( array( 'query' => $connected_posts) );
endif;
I’m trying to get the authors to show with pagination working. Any assistance would be much appreciated.
Thanks,
Brian
https://www.ads-software.com/plugins/posts-to-posts/
]]>Here is the code I’m using:
<?php
$args = array (
'post_type' => 'hhie_albums',
);
$query_albums = new WP_Query( $args );
p2p_type( 'albums_to_producers' )->each_connected( $query_albums, array(), 'producers' );
p2p_type( 'albums_to_artists' )->each_connected( $query_albums, array(), 'artists' );
if ($query_albums->have_posts() ) {
while ($query_albums->have_posts() ) { $query_albums->the_post();
foreach ( $post->artists as $post ) : setup_postdata( $post );
the_permalink();
endforeach;
wp_reset_postdata();
foreach ($post->producers as $post) : setup_postdata( $post );
the_permalink();
endforeach;
wp_reset_postdata();
}
wp_reset_postdata();
} else {
echo 'Massive fail';
}
?>
Note that if I remove the first foreach loop (artists), then the second (producers) works fine. Anyone encountered the same issue?
https://www.ads-software.com/plugins/posts-to-posts/
]]>abc_person
and abc_animal
) show up fine in the admin interface, but not when I try to retrieve and render them on the archive pages for the custom post types.
I am registering as follows:
p2p_register_connection_type(array(
'name' => 'persons_to_animals',
'from' => 'abc_person',
'to' => 'abc_animal',
'cardinality' => 'one-to-many',
'sortable' => 'any'
));
Then I create connections, which show up as expected in the WP admin interface.
But then, on the archive-abc_person
template, regardless of whether I use
$connected = get_posts(array(
'connected_items' => $wp_query->posts,
'connected_type' => 'persons_to_animals',
'connected_direction' => 'from',
'nopaging' => true,
'suppress_filters' => false
));
p2p_distribute_connected($wp_query->posts, $connected, 'connected');
if (have_posts()) : while (have_posts()) : the_post();
...etc...
or
p2p_type('persons_to_animals')->each_connected($wp_query);
if (have_posts()) : while (have_posts()) : the_post();
...etc...
I always receive an empty array back as $post->connected
The archive template is otherwise plain and doesn’t have any other relevant code in it that would affect the loop.
What am I doing wrong?
https://www.ads-software.com/plugins/posts-to-posts/
]]>I have a problem in the homepage of my website.
I have custom post types (scene and movies) and I want to display only scenes in my home and the movie title of the scene. I have defined the relation between those custom posts
The problem is that if I add a filter to my query in order to display scenes like that :
$wp_query = new WP_Query( array(
'post_type' => 'scene'
) );
It will display scenes but the relationship between scenes and movies won’t be established. I tried all the solutions of the documentation () but whitout success.
The relation between scenes and movies works if I set “scenes” AND “movies” in my custom query. But I don’t want the movies displayed in my homepage.
Could you help me please?
https://www.ads-software.com/extend/plugins/posts-to-posts/
]]>i am developing a site between my local development server and two remote servers (test and production) each server has its own wp instance its own database.
my workflow is to move the entire database between servers, and tweak the wp-options table (rows home and siteurl). thus, post ids, settings etc. are as identical as possible between the servers. code is kept in sync with git for my files and svn for wordpress files.
this loop works great on my local dev machine
`p2p_type( ‘pioneer-to-person’ )->each_connected( $wp_query );
while (have_posts()) {
the_post();
$profileLink = get_permalink();
foreach ( $post->connected as $post ){
setup_postdata( $post );
render_template_file(‘excerpt’, ‘type-career-profile’);
}
}`
when i deploy to my test server, the code fails at the foreach call
PHP Warning: Invalid argument supplied for foreach() in archive-career-profile.php
since the data ‘should’ be the same between the servers, i’m stumped.
the only thing (so far) i’ve found is my dev machine (where it works) is php 5.3.15 and the test/production servers (where it fails ) are at 5.3.3
i HUGELY appreciate any help or suggestions on where to look.
thanks again for reading this post and for the excellent plugin.
https://www.ads-software.com/extend/plugins/posts-to-posts/
]]>I created 2 relationships:
scene2acteur
movie2scene
An actor can play in a scene and a scene is in a movie
When I am on the actor page, I want to display link like this :
movie1
scene1
scene2
movie2
scene1
movies and scenes are links. This is the code I made, inspired by the example of the wiki
$my_query = new WP_Query( array(
'post_type' => 'acteur'
) );
p2p_type( 'scene2acteur' )->each_connected( $my_query, array(), 'scene' );
while ( $my_query->have_posts() ) { $my_query->the_post();
// Another level of nesting
p2p_type( 'movie2scene' )->each_connected( $post->scene, array(), 'movie' );
foreach ( $post->scene as $post ) {
setup_postdata( $post );
echo '<pre>' ;print_r($post); echo '</pre>';
the_title();
echo ' --- films ---';
foreach ( $post->movie as $post ) { setup_postdata( $post );
the_title();
}
}
wp_reset_postdata();
}
My first problem is that I have to find each scene before finding attached films. The scenes must be grouped by movie
My second problem is that I don’t manage to modify the_title(); into a real link like this
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
thank you for your help
https://www.ads-software.com/extend/plugins/posts-to-posts/
]]>I have a post type “Movie,” and I need to display a list of connected post type “Scene.” With each Scene, I need to display connected post types “Director” and “Performer.”
I’ve tried all of the methods on https://github.com/scribu/wp-posts-to-posts/wiki/each_connected and each presents a similar problem: It will return Scenes, and it will return the first connected post type below that. The second will generate an error. For the preferred method (each_connected), the error is: Invalid argument supplied for foreach()… on the line of the second foreach() call. Doesn’t matter which is second.
Here’s my current code. I’ve tinkered with it all day, and even switched to the nested WP_Queries method (that gave me a “no direction(s) error… again, on the second query only).
<?php
// Find connected posts
$scenes = new WP_Query( array(
'connected_type' => 'movie_to_scene',
'connected_items' => get_queried_object(),
'nopaging' => true
) );
p2p_type( 'performer_to_scene' )->each_connected( $scenes, array(), 'joy_performer' );
p2p_type( 'director_to_scene' )->each_connected( $scenes, array(), 'joy_director' );
if ( $scenes->have_posts() ) :
while ( $scenes->have_posts() ) : $scenes->the_post(); ?>
<div class="row-fluid">
<div class="span3">
</div>
<div class="span9 entry-content">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<!-- scene info -->
<?php
foreach ( $post->joy_performer as $post ) : setup_postdata( $post );
the_title();
endforeach;
wp_reset_postdata();
foreach ( $post->joy_director as $post ) : setup_postdata( $post );
the_title();
endforeach;
wp_reset_postdata();
?>
<!-- /scene info -->
</div>
</div>
<?php endwhile; wp_reset_postdata(); endif; ?>
]]>Could you please show me one example of how to use each_connected with posts-to-users?
Thank you.
https://www.ads-software.com/extend/plugins/posts-to-posts/
]]>First off, thanks a lot for the plug-in – seems perfect for what I’m trying to do.
I modified the Looping the Loop example (https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop) for using each_connected multiple times.
I have 3 cpt – recipes, tips and chefs. For each recipe I’m trying to display information about the connected tips and chefs.
In the code below, the recipe title and tip title appear, but nothing appears for the chef posts. If I comment out the foreach & wp_reset_postdata() code for the tip posts, then the chef post data does appear. I’m totally stumped on this one so any help would be greatly appreciated!
The code is either https://pastebin.com/yz7gfUVY or below.
`
<?php
$my_query = new WP_Query( array(
‘post_type’ => ‘recipes’
) );
p2p_type( ‘recipes_to_tips’ )->each_connected( $my_query, array(), ‘tips’ );
p2p_type( ‘recipes_to_chefs’ )->each_connected( $my_query, array(), ‘chefs’ );
?>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<p>The Recipe</>
<?php the_title(); ?>
<?php
// Display connected tip
echo ‘<p>Tip:</p>’;
foreach ( $post->tips as $post ) : setup_postdata( $post );
the_title();
endforeach;
wp_reset_postdata();
// Display connected chef
echo ‘<p>Chef:</p>’;
foreach ( $post->chefs as $post ) : setup_postdata( $post );
the_title();
endforeach;
wp_reset_postdata();
?>
<?php endwhile; ?>
`
https://www.ads-software.com/extend/plugins/posts-to-posts/
]]>