WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
How To Add Info to Connection (78 posts)

  1. Modesty
    Member
    Posted 3 years ago #

    By using p2p_get_meta(). See here: http://scribu.net/wordpress/posts-to-posts/p2p-0-5.html

    yes I've tried that but with no results... here is my query... where and how would you insert p2p_get_meta:

    global $post;
    $sc_query = new WP_Query( array(
      'suppress_filters' => false,
      'post_type' => 'post',
      'connected' => $post->ID,
    
    ) );
    
    if($sc_query->have_posts()) :
    
    echo '<ul>';
    
    while($sc_query->have_posts()):$sc_query->the_post();
    
    $sc_output ='';
    $sc_output .= '<li><a href="' . get_permalink($post->ID) . '">';
    $sc_output .= $post->post_title;
    $sc_output .= '</a></li>';
    
    echo $sc_output;
    
    endwhile;
    
    echo '</ul>';
    
    endif;
  2. Modesty
    Member
    Posted 3 years ago #

    Regarding duplication, there are two ways to achieve the multiple-role scenario

    I would go with A... in that case a single query works...

  3. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    while($sc_query->have_posts()):$sc_query->the_post();
    
      $sc_output = '';
      $sc_output .= '<li><a href="' . get_permalink($post->ID) . '">';
      $sc_output .= $post->post_title;
    
      $sc_output .= ' ' . p2p_get_meta( $post->p2p_id, 'date', true );
    
      $sc_output .= '</a></li>';
    
    ...
    endwhile;

    Obviously, replace 'date' with your meta key.

  4. Modesty
    Member
    Posted 3 years ago #

    great!!!

    and does this still work:

    $my_query = new WP_Query( array(
        'post_type' => 'book',
        'connected_to' => 'any',
        'connected_meta' => array(
            'connection_date' => 'long ago',
        )
    ) );
  5. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    In the time it took you to ask that question, you could have just tried it and see for yourself.

  6. Modesty
    Member
    Posted 3 years ago #

    well, I actually did before I asked but it didn't work out...
    so I presumed something might be wrong with my code ergo - the question

  7. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    It works for me. Try 'connected_from' => 'any'.

  8. Modesty
    Member
    Posted 3 years ago #

    if the metadata value of the field in the query contains diacritics - the search returns nothing.

    that's why it didn't work.

  9. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Good to know.

  10. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    To allow duplicate connections:

    0. Re-download the development version.

    1. Add 'prevent_duplicates' => false to p2p_register_connection_type():

    p2p_register_connection_type( array(
    	'from' => 'post',
    	'to' => 'page',
    	'prevent_duplicates' => false,
    ) );
  11. Modesty
    Member
    Posted 3 years ago #

    will the pre-exiting connections stay intact?

  12. Modesty
    Member
    Posted 3 years ago #

    after some testing - from what i see - they will

  13. Modesty
    Member
    Posted 3 years ago #

    Scribu, is there a way to use this with your front end editor?

  14. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Erm, I don't understand what you mean. Also, please open a new topic.

  15. e-duplex
    Member
    Posted 3 years ago #

    Hi scribu! Is it posible to join wp_p2pmeta in the WP_Query? Because the only way that I found to access to meta_value field is to call p2p_get_meta() in the loop. But each call of p2p_get_meta() is a new query to de DB...
    It is only a little doubt, your plugin it is terrible!

  16. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    My plugin is terrible? Gee, thanks...

    I suppose I should query all the p2p meta in one go.

  17. e-duplex
    Member
    Posted 3 years ago #

    Sorry! It was incomplete. I meant terribl....y wonderful!

  18. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    The development version (0.8-alpha) now caches all connection information beforehand.

    Should reduce the number of queries when using p2p_get_meta().

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic