• I’d like to connect the locations post type with the product post type created by woocommerce using posts-to-posts.
    I’ve been able to register a connection type using:
    ‘ /** Connecting Posts to Posts and Pages such as Locations to Shop Products. */
    function my_connection_types() {
    p2p_register_connection_type( array(
    ‘name’ => ‘locations_to_product’,
    ‘from’ => ‘location’,
    ‘to’ => ‘product’
    ) );
    }
    add_action( ‘p2p_init’, ‘my_connection_types’ ); ‘

    I then added this code to single-location.php:
    ‘ /* Connect a location to products */
    $connected = new WP_Query( array(
    ‘connected_type’ => ‘locations_to_product’,
    ‘connected_items’ => get_queried_object()
    ) );

    echo ‘<p>Related products:</p>’;
    echo ‘

      ‘;
      while( $connected->have_posts() ) : $connected->the_post();
      echo ‘

    • ‘;
      the_title();
      echo ‘
    • ‘;
      endwhile;
      echo ‘

    ‘;

    wp_reset_postdata(); ‘

    The meta boxes are in place but for some reason they seem to take me to the top of the page every time without allowing me to create the connections.
    Any ideas on how to solve this?

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

  • The topic ‘Connecting CPTs’ is closed to new replies.