WordPress.org

Support

Support » Plugins and Hacks » Posts 2 Posts » [Resolved] [Plugin: Posts 2 Posts] WP_Query() x get_posts()

[Resolved] [Plugin: Posts 2 Posts] WP_Query() x get_posts()

  • These values are in database table:

    id,from,to
    2,2478,3910
    3,4075,3910

    I tried to connect posts to pages, so there are two posts (2478 and 4075) connected to page 3910.

    Then I wanted to list connected posts to my page:

    $sc_query = new WP_Query( array(
      'suppress_filters' => false,
      'post_type' => 'post',
      'connected_to' => $post->ID) );
    
    if($sc_query->have_posts()) :
    
    echo '<ul>';
    
    while($sc_query->have_posts()):$sc_query->the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    
    <?php
    endwhile;
    echo '</ul>';
    endif;
    wp_reset_query();

    $post->ID is correct 3910, but there are both connected posts with many others? I do not understand why, because in p2p table are only these 2 rows?

    And when I use get_posts(), everything works well:

    $connected = get_posts( array(
      'suppress_filters' => false,
      'post_type' => 'post',
      'connected_to' => $post->ID,
    ) );
    
    echo '<ul>';
    
    foreach( $connected as $post ) : setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach;
    
    echo '</ul>';

    I am out of ideas… Same query, different results?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Oh, probably my mistake, not related to Posts 2 Posts plugin, but interesting…

    Problem was related to parametr caller_get_posts which was false by default, but I had there many sticky post and so they were passed automatically into WP_Query()…

    Adding 'caller_get_posts' => true solved my troubles…

    Plugin Author scribu

    @scribu

    Yeah, makes sense, since get_posts() automatically sets some parameters.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] [Plugin: Posts 2 Posts] WP_Query() x get_posts()’ is closed to new replies.
Skip to toolbar