Skip Navigation

[Closed] Query repeatable field with query arguments

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)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 8 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2698335
Screenshot 2024-05-17 at 8.30.15 PM.png

Dear Sir/Madam,

I have a custom post with repeatable field, I use toolset_get_related_posts() to query the repeatable records, I want to query the repeatable record with specific query arguments, timeslot is the repeatable field including application-id and timeslot-status, I want to query all record if application-id is empty or not exist, could you please advise how I can do

$reservation_ids = toolset_get_related_posts( $booking_id, 'timeslot', 'parent', 100, 0, array(), 'post_id', 'child');

I guess I should customize the array() within this toolset_get_related_posts() but no idea how, could you help?

#2698617

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I would like to know you want to get posts where if application-id is empty or not exist for any specific booking detail (booking ID) or all the posts where application-id is empty or not exist irrespective of booking ID?

#2698712

For all child booking related to the booking_id where application-id is empty or not exist

#2698772

Minesh
Supporter

Languages: English (English )

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

What if you try to use the following code:


	$post_meta = array('meta_key' => 'wpcf-application-id',
			   'meta_compare' => '=',
			   'meta_value' => '');
						
	  
	$reservation_ids = toolset_get_related_posts( $booking_id, 'timeslot', 'parent', 999, 0, $post_meta, 'post_id', 'child');

The variable $reservation_ids should contain the post IDs where application ID is empty.

Now do you mean that if booking ID does not have any related timeslot repeating field group item you want those records as well?

#2700014
Screenshot 2024-05-30 at 12.46.45 AM.png
Screenshot 2024-05-30 at 12.42.14 AM.png

Dear Minesh,

Thanks for your reply. I want to have AND condition to the post_meta() but not work, please advise what's wrong to my code snippet

		$post_meta = array(
			'relation' => 'AND',
			array(
				'meta_key' => 'wpcf-application-id',
				'meta_compare' => '=',
				'meta_value' => '',
			),
			array(
				'meta_key' => 'wpcf-timeslot-status',
				'meta_compare' => '=',
				'meta_value' => '1',
			),			
		);

		$reservation_ids = toolset_get_related_posts( $booking_id, 'timeslot', 'parent', 999, 0, $post_meta, 'post_id', 'child');

Refer to the screenshots, I want the query will only return the timeslot has no application id and timeslot-status is available, there are 3 timeslots, it should only return the 2 but my above query return all.

#2700123

Minesh
Supporter

Languages: English (English )

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

It should work I'm not sure why its not working.

Can you please tell me where exactly you added the code as well as where exactly you want to display the results.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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.

#2700940

Dear Minesh,

As website is still under development, no public access to it. Any alternative solution?

#2700945

Minesh
Supporter

Languages: English (English )

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

Another alternative is you can share the site copy using duplicator:
- https://toolset.com/faq/provide-supporters-copy-site/
OR
- https://wordpress.org/plugins/all-in-one-wp-migration/

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

The topic ‘[Closed] Query repeatable field with query arguments’ is closed to new replies.