WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] triple nesting, connections of drafts (3 posts)

  1. econofast
    Member
    Posted 1 year ago #

    I realized that my previous post was on a resolved message - sorry about that! And this is a rather different question anyway...

    I am looping through 3 post types: Timeslot, Session, Speaker, and I want to show all of them, regardless of post status.
    I am able to display all of the timeslots (which are all live) and sessions, but when I get to speakers, they only show up on published sessions.

    Is there a way to show draft speakers that are connected to draft sessions?

    Here is a simplified version of my code:

    <?php
    $my_query = new WP_Query( array( 'post_type' => 'timeslot' ) );
    p2p_type( 'timeslots_to_sessions' )->each_connected( $my_query, array('post_status' => 'publish, draft'), 'sessions' );
    while ( $my_query->have_posts() ) : $my_query->the_post();
    ?>
    <div class="timeslot">
    <?php the_title(); ?>
    <div class="sessions">
    <?php
    p2p_type( 'sessions_to_speakers' )->each_connected( $post->sessions, array('post_status' => 'any'), 'speakers' );
    foreach ( $post->sessions as $post ) : setup_postdata( $post );
    	echo '<div class="sessionrow">';
    ?>
    <div class="sessionbox">
    <?php the_title(); ?>
    <?php
    the_content();
    	if(!empty($post->speakers)){
    		echo '<div class="speakers"><ul>';
    		foreach ( $post->speakers as $post ) : setup_postdata( $post );
    			echo("<li>" . get_the_title() );
    			echo(types_render_field("jobtitle") ? ", " . types_render_field("jobtitle") : "");
    			echo(types_render_field("company") ? ", " . types_render_field("company") : "");
    			echo("</li>");
    		endforeach;
    		echo('</ul> </div>');
    	}
    	echo "</div>";
    
    endforeach;
    echo '</div>';
    wp_reset_postdata();
    	?>
    </div></div>
    
    <?php
    endwhile; ?>

    (Note that "types_render_field" is a function provided by the wp-types plugin to display custom fields. That shouldn't have any effect.)

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

  2. econofast
    Member
    Posted 1 year ago #

    For anyone else dealing with something like this:
    It turns out that my code above is correct (aside from perhaps some div nesting mistakes due to hasty simplifying), and the culprit isn't related to the extra connection nesting.
    In order to show items that are connected to non-published posts, you need to add the following to your p2p_register_connection_type:
    'from_query_vars' => array('post_status' => 'any')
    It's just that simple!

  3. kemie
    Member
    Posted 1 year ago #

    THANK YOU! it was actually to_query_vars that I needed, but your post got me going in the right direction. You´re a lifesaver!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic