WordPress.org

Support

Support » Plugins and Hacks » Posts 2 Posts » [Resolved] [Plugin: Posts 2 Posts] bbpress and custom post type relationships didnt work

[Resolved] [Plugin: Posts 2 Posts] bbpress and custom post type relationships didnt work

  • I tried to connect bbpress “reply” custom post type with my “urun” named custom post type.

    Admin sections works normally but i couldnt get it work on front-end.
    bbpress/loop-replies.php have this action filter: bbp_theme_after_reply_content action

    function related_urun_cevap() {
    global $my_connection_type;
    
    // Find connected posts
    $connected = $my_connection_type->get_connected( get_queried_object_id() );
    
    // Display connected posts
    if ( $connected->have_posts() ) :
    ?>
    <h3>Related posts:</h3>
    <ul>
    <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    
    <?php
    // Prevent weirdness
    wp_reset_postdata();
    
    endif;
    }
    add_action( 'bbp_theme_after_reply_content', 'related_urun_cevap' );

    what is problem?

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

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author scribu

    @scribu

    Are you sure get_queried_object_id() is what you expect?

    well.. tried $post->ID too.. I really cant think what it should be

    global $bbp;
    echo $bbp->current_reply_id;

    this echoes id successfully but still that loop not works with $bbp->current_reply_id

    Plugin Author scribu

    @scribu

    So you’re doing:

    $connected = $my_connection_type->get_connected( $bbp->current_reply_id );

    Does p2p_list_posts( $connected ); work?

    nope.. not working..

    function related_urun_cevap() {
    global $bbp;
    global $my_connection_type;
    
    // Find connected posts
    $connected = $my_connection_type->get_connected( $bbp->current_reply_id );
    
    // Display connected posts
    if ( $connected->have_posts() ) :
    	echo '<h3>Related posts</h3>';
    	p2p_list_posts( $connected );
    endif;
    
    //echo $bbp->current_reply_id;
    }
    add_action( 'bbp_theme_after_reply_content', 'related_urun_cevap' );
    Plugin Author scribu

    @scribu

    The problem is that the first reply is actually a topic. So $bbp->current_reply_id is null, so get_connected() returns false.

    If you had error reporting turned on, you would have seen a fatal error when you try to call have_posts() on a non-existing object.

    Long storry short, just check current_reply_id before doing anything else:

    function related_urun_cevap() {
    	global $bbp, $my_connection_type;
    
    	// First reply is actually a topic
    	if ( !$bbp->current_reply_id )
    		return;
    
    	// Find connected posts
    	$connected = $my_connection_type->get_connected( $bbp->current_reply_id );
    
    	// Display connected posts
    	if ( $connected->have_posts() ) {
    		echo '<h3>Related posts</h3>';
    		p2p_list_posts( $connected );
    	}
    }
    add_action( 'bbp_theme_after_reply_content', 'related_urun_cevap' );

    Thank you 🙂
    Last question:
    is there any way to remove p2p-tab-create-post panel?
    i temporary added

    .p2p-tab-create-post {
        display: none !important;
    }

    which is ugly solution tbh..

    Plugin Author scribu

    @scribu

    With the development version (0.9.6-alpha), you can do this:

    p2p_register_connection_type( array(
      ...
      'can_create_post' => false
    ) );

    thanks 🙂

    if you have a showcase list of your plugin, you can add this site:
    http://kremim.com/soru/bioderma-photoderm-akn-mat-spf-30-krem/
    http://kremim.com/soru/lutfen-cvp-verirmisiniz/
    etc..

    Those are bbpress forum topics that an expert answering questions and linking related products.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] [Plugin: Posts 2 Posts] bbpress and custom post type relationships didnt work’ is closed to new replies.
Skip to toolbar