Plugin Author
scribu
(@scribu)
Thread Starter
argeee
(@argeee)
Hi Scribu,
I don’t thinks that I explained my question correctly. The first loop is not a p2p loop. Meaning its a wp loop. The second one is a p2p loop. My problem is that if I do a WP_Query on before the p2p, p2p outputs nothing, whereas if I do it after everything is OK. Please see a summarized version of my code:
$wp_query = new WP_Query(array(
'post_type' => 'client',
'client_type' => 'Distributor'));
while ($wp_query->have_posts()) : $wp_query->the_post();
echo '<h2>' . the_title() . '</h2>'; //just testing if outputs
endwhile;
wp_reset_postdata();
$connected = new WP_Query( array(
'post_type' => 'ups',
'connected_from' => get_the_ID(),
'nopaging' => true,
'suppress_filters' => false
) );
?>
<div id="products_wrapper">
<h3><?php _e('you may also be interested in...','eq_power') ?></h3>
<?php
// if ($connected->have_posts()) :
while( $connected->have_posts() ) : $connected->the_post();
?>
<div class="products_item_wrapper">
<?php echo '<h2>' . the_title() . '</h2>'; //just testing if outputs?>
</div>
<!-- end products_item_wrapper -->
<?php endwhile;
wp_reset_postdata();?>
<!-- end products_wrapper -->
thanks,
Mauro
Plugin Author
scribu
(@scribu)
The problem is that get_the_ID() is meant to be used within The Loop.
Try replacing it with get_queried_object_id() or storing it in a temporary variable before the non-p2p query.
Thread Starter
argeee
(@argeee)
Yep, it worked. I used the following:
$temp_prod_ID= get_queried_object_id();
and then substituted get_the_ID() as follows:
$connected = new WP_Query( array(
'post_type' => 'ups',
'connected_from' => $temp_prod_ID,
'nopaging' => true,
'suppress_filters' => false
) );
PS.
How you give better support than for most paying plugins is something that is beyond me…
Anyway, I made a small contribution for all the help that you’ve been giving me.
Thanks again,
Mauro