WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] bbpress and custom post type relationships didnt work (10 posts)

  1. Unsal Korkmaz
    Member
    Posted 2 years ago #

    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/

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Are you sure get_queried_object_id() is what you expect?

  3. Unsal Korkmaz
    Member
    Posted 2 years ago #

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

  4. Unsal Korkmaz
    Member
    Posted 2 years ago #

    global $bbp;
    echo $bbp->current_reply_id;

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

  5. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    So you're doing:

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

    Does p2p_list_posts( $connected ); work?

  6. Unsal Korkmaz
    Member
    Posted 2 years ago #

    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' );
  7. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    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' );
  8. Unsal Korkmaz
    Member
    Posted 2 years ago #

    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..

  9. scribu
    Member
    Plugin Author

    Posted 2 years ago #

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

    p2p_register_connection_type( array(
      ...
      'can_create_post' => false
    ) );
  10. Unsal Korkmaz
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic