Support

Account

Home Forums General Issues Query with Relationship field Reply To: Query with Relationship field

  • Hi James

    Thank you for your help, it works !

    I’ve tried with an array of ID, it doesn’t work, it returns an empty array.

    Here is what I’ve done, unfortunately it doesn’t work…
    Do you have an idea ?

    Thank you very much for your time.

    <?php 
    
    $preargs = array(
      'post_type'  => 'offres'
     );
    
    $the_query = new WP_Query( $preargs ); 
    $offres_id = array(); //added
    
    while ( $the_query->have_posts() ) : $the_query->the_post();
     $offres_id[] = get_the_ID();
    endwhile; 
    
    // $arraydeidoffre RETURNS : array(7) { [0]=> int(25747) [1]=> int(25356) [2]=> int(24140) [3]=> int(23097) [4]=> int(23054) [5]=> int(22286) [6]=> int(12005) } 
    
    $propositions = get_posts(array(
         'post_type' => 'proposition',
         'numberposts' => -1,
         'meta_query' => array(
          array(
           'key' => 'offre_liee', 
           'value' => $offres_id, 
           'compare' => 'IN'
          )
         )
    
        ));
    
    var_dump($propositions);
    
    ?>