Skip Navigation

[Resolved] toolset_get_related_posts() with condition query

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 1 year, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#2480535
Screenshot 2022-10-21 at 3.04.35 PM.png

Dear Sir/Madam,

Refer to the screenshot, a member purchase several coupons package, how can I get the one coupons with below condition
1. ignore all balance is 0
2. the earliest purchase date

How can I add above query to the tooset_get_related_posts()?

        $child_posts = toolset_get_related_posts( $_REQUEST['m'], 'member-coupon', array( 'query_by_role' => 'parent', 'return' => 'post_object', 'limit'=> 1));
        foreach ($child_posts as $child_post) {
            
            $this_post_id = $child_post->ID;
            
            $this_total_coupons = types_render_field('coupon-purchased-quota', array("id"=> "$child_post->ID"));
            $this_coupon_balance = types_render_field('coupon-quota-balance', array("id"=> "$child_post->ID"));
            $this_used_coupons = $this_total_coupons - $this_coupon_balance;
            
            $this_coupon = new Coupon($_REQUEST['m'], $this_total_coupons, $this_coupon_balance);
            $this_coupon->set_image('/images/stamp.png');
            $has_coupon = true;
        }

#2482307

Hello,

You can follow our document to setup the WP query:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

See the example in section "NEW APPROACH", and you can follow WP document to setup other filter parameters and order by parameters:
https://developer.wordpress.org/reference/classes/wp_query/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.