WordPress.org

Forums

Posts 2 Posts
Can't get it working. (4 posts)

  1. jhazelh
    Member
    Posted 1 year ago #

    Hello guys,

    I'm developing a website but i'm running into some problems.
    I have 2 custom post types : Producten and Clients. I made a connection between those 2 in functions.php:

    function my_connection_types() {
    p2p_register_connection_type( array(
    'name' => 'client_to_products',
    'from' => 'klanten',
    'to' => 'producten'
    ) );
    }
    add_action( 'p2p_init', 'my_connection_types' );

    Then on my template where i got post 'klanten' (Clients) my connection seems to work fine. But when i go to single-klanten.php
    i won't get it working:
    <?php
    $connected = new WP_Query( array(
    'connected_type' => 'client_to_products',
    'connected_items' => array(get_the_id()),
    'nopaging' => true,
    ) );
    if ( $connected->have_posts() ) :
    ?>

      <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>

    • <?php the_title(); ?>
    • <?php endwhile; ?>

    <?php else: ?>
    <p>geen producten gevonden gevonden</p>
    <?php
    wp_reset_postdata();
    endif;
    wp_reset_query();
    ?>

    The link if it helps:
    http://www.icreative.nl/klanten/akzonobel/

    https://wordpress.org/plugins/posts-to-posts/

  2. Daniel King
    Member
    Posted 1 year ago #

    Hi jhazelh,
    I'm writing this without checking it first, so I'm not sure if this will help, but did you check it the Reciprocal option?
    https://github.com/scribu/wp-posts-to-posts/wiki/Reciprocal-connections

  3. jhazelh
    Member
    Posted 1 year ago #

    Hello Daniel,

    Thanks for responding m8.
    I will check it out and let you know if it worked.

  4. EliasNS
    Member
    Posted 1 year ago #

    I think the reciprocal parameter would be useful for something like 'product related to another product', but nothing to do in this case, I suspect.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic