Support

Account

Home Forums Front-end Issues WP_query for each loop Reply To: WP_query for each loop

  • Think that I asked the wrong question, or didn’t put all info (!duh).

    I have two CPTs: Products & tools. In Products you can select related tools using the relationship field.

    The tools have a radio button (wheel_section). On the product page I want to get all relationships and display them in groups based on the value of wheel_section.

    Been searching, racking my brain, biting my nails, etc. but cannot work out how to do this. This is how far I have got – if anyone can point me in the right direction would be very grateful.

    1) Get related posts
    <?php $posts = get_field('product_tools'); if( $posts ): ?>

    2) Look through posts / setup data

    <?php $i=0; foreach( $posts as $post): ?>
     <?php setup_postdata($post); ?>

    3) Get choices from wheel_section radio button
    <?php echo implode(', ', get_field_object('wheel_section')[choices]); ?>

    4) Loop through choices
    This is where I get lost. Now I have an array and I need to loop through each choice and get corresponding label and calculators so I get:

    WHEEL SECTION LABEL 1
    – calculators in wheel section 1

    WHEEL SECTION LABEL 2
    – calculators in wheel section 2