WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
each_connectd with 3 relationship (3 posts)

  1. skapiso
    Member
    Posted 1 year ago #

    Hello, I discovered your plugin a few days ago and this is what I was looking for but I have a question.

    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

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. schwarzgrau
    Member
    Posted 1 year ago #

    To the second problem:

    replace
    the_title();
    with

    echo'<li><a href="'.the_permalink().'">'.get_the_title().'</a></li>
    ';
  3. skapiso
    Member
    Posted 1 year ago #

    ok thank you I will this.

    For my first problem, i really don't know how to resolve it.

    I want to organise my links by movies when I am on an actor page but actor and movies are not directly linked.
    an actor is linked to a scene only. and a scene is linked to a movie.

    So I have to get first the scene in where the actor plays to and only after this step I can get the movie.

    I could reorganise the loop to change the display but I don't know how to group scenes under a same movie

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic