Skip Navigation

[Resolved] Select from a CPT and filter by repeatable field

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Author
Posts
#1584119

Hi,
I'm trying to select from a CPT (slug: 'raw-material') the rows which have the value 'TOP NOTES' in wpcf-volatility-rmt (as a custom field).
After that I would process the rows obtained filtering by a specific meta_value of a repeatable field (slug: type-fragapp-rmt-rg) that is in a RFG of the same CPT (slug: 'raw-material') named 'rmt-rg-frag-app' (as slug).
How I can solve the issue? Have you suggestions?
Thank you very much in advance for your support.

This is the code that I tested without results. Is the first section of TOP NOTES; the page will contain three different section TOP NOTES, MIDDLE NOTES and BASE NOTES with the same code replicated. I will change only the "value' => 'TOP NOTES'" in the first query with MIDDLE NOTES and BASE NOTES.

<?php

        $args = array(
                'post_type' => 'raw-material',
                'field' => 'ids',
                'posts_per_page' => 50,
                'meta_query' => array(
                        array(
                            'key' => 'wpcf-volatility-rmt',
                            'value' => 'TOP NOTES',
                            'compare' => 'LIKE'
                        )
                    )

                );

              $query = new WP_Query($args);
              while ( $query->have_posts() ) : $query->the_post();

          $child = array();
         
            $child[] = toolset_get_related_post(                 
            get_the_ID(),
            'rmt-rg-frag-app',   
            'parent',     
            100,     
            0,           
            array(
                         'meta_key' => 'wpcf-type-fragapp-rmt-rg',
                         'meta_value' => 'cherry',
                         'meta_compare' => 'LIKE'
                       ),

          'post_object',   
          'child',    
          '',
          'ASC'
         );

          $query_ch['post__in'] = $child;
          return $query_ch;

         ?>

                     <div class="post clearfix">
                                 <h5><?php echo the_ID(); ?></h5>
                                 <h5><?php echo the_title(); ?></h5>
                                 <h6><?php echo $txt_fragr_type; ?></h6>
                                 <h6><?php echo 'founded'; ?></h6>
                                 <h6><?php echo types_render_field( "volatility-rmt", array($query));?></h6>
                                 <h6><?php echo types_render_field( 'type-fragapp-rmt-rg', array($query_ch) );?></h6>

                     </div>
#1584705

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

It seems the code you shared is not the full code you are using as I do not see the end while that ends the while loop.

I do not know why you use the return statement as well: return $query_ch;

If you can share problem URL and access details and tell me where exactly to which file you have added the above code I will further look at it and try to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1585097

Hi Minesh,
thanks for your reply.
I posted the piece of code that could be wrong.
The first query is ok and i can see the correct result (filtering by volatility).
The while loop is frustrating 🙂
The toolset_get_related_post args are correct?

I'm sorry but during the cleanup of the code before posting I deleted some lines and uncommented others.
I'm testing this function in localhost. Is necessary a test in real conditions?
Thank you Minesh for your support.

#1585101

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As per the doc toolset_get_related_posts() API function the code you shared looks ok.
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

But again I still wonder, why you have added a return statement? return $query_ch;
- As the control will be return from that vary line of code and the next code lines you have added will not be executed.

It's hard for me to guide you in the right direction without the test site where I can see the issue as it can be anything.

As you are using the foreach loop and within foreach loop you are trying to get the related repeating field group posts (so it is possible that the toolset_get_related_posts() will return many results) so you will need another foreach loop to display the content of your related posts.

#1585201

Minesh,
I'll upload the file in my remote server in the next hours and I'll give you the credentials to test everything.
Many many thanks for your support.

#1585203

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sure, Please send me information that what field values you want to display exactly where and where the file I can find where you added the code you shared.

I have set the next reply to private which means only you and I have access to it.

#1587275

Hi Minesh,
Tonight I tested the get_related_posts function with a different code and a foreach iteration of the array. I solved my issue and no need to spend your time.
Thanks of all.

#1587281

My issue is resolved now. Thank you!