Skip Navigation

[Resolved] Front-end post submission form in a grandchild relationship

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 3 replies, has 1 voice.

Last updated by Minesh 1 week ago.

Assisted by: Minesh.

Author
Posts
#2818546

Hi,

I am developing a lottery tickets booking platform for groups of people. I have created a new user role that can create new groups or organizations. So, this role is able to create custom posts “Organizations”. Once a new Organization’s post is created, the link is shared by the Organization’s owner to all the group members externally to the platform.

Organizations have a one to many relationship with another custom post which is Numbers. This Numbers post stores the lottery number (post title), the amount of lottery shares, the bookings final date and the inventory of the remaining lottery shares.

Numbers have a one to many relationship with another custom post which is Bookings. This Booking post stores the booked amount and the booker’s personal data.

So, what I have is this one to many relationship structure:

Organizations → Numbers → Bookings

When a booker accesses the Organizations page, a front-end form is displayed to allow booking as many lottery tickets of the same number as desired. This form has a select field which should display Organization’s Numbers with the following restrictions:

The Numbers displayed must belong to the Organization (relationship Organizations → Numbers)
The Number’s lottery ticket inventory must be greater than 0.
The current date must be lower or equal to the bookings final date for the displayed Number.

All the above structure has been created and tested. However, the select field displays all the Numbers in the platform without any restriction related to Organization, inventory or date.

How should I configure this select field to match the above conditions?

Thank you.

#2818552

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - there are multiple ways but once I check the actual setup I will be able to guide you what would be the best option to go with.

Can you please share admin access details as well as login access details for booker user and setup a test organization and share link where I can see the form as well as tell me what is your expected result with the select field on that page with that booker user.

*** 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.

#2818572

Minesh
Supporter

Languages: English (English )

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

Can you please share problem URL and tell me where I can see the form?

Also, Can you please share admin access details and frontend user booker user access details so I can login as Booker user and access the form and on that form what is your expected output with the parent dropdown select field?

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

#2818893

Minesh
Supporter

Languages: English (English )

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

Can you please check now.

I've added the following code to "Custom Code" section with the code snippet namely "toolset-custom-code":
=> hidden link

function func_filter_parent_relationship_dropdown_select2($query){
    global $post;
    
 
    if (defined('DOING_AJAX') && DOING_AJAX and isset($_REQUEST['action']) and isset($_REQUEST['slug']) and isset($_REQUEST['form_type'])    ) { 
     
        $parent_post_type = 'numero';  /// parrent post type slug
        $relationship_slug = 'numero-reserva'; ///relationship slug
         
      
       if($_REQUEST['action']=='select2_potential_relationship_parents' and $_REQUEST['slug']==$relationship_slug){
              
            if($query->query['post_type'][0]==$parent_post_type ){
              	
              	$current_post_id = url_to_postid( $_SERVER['HTTP_REFERER'] );
           
              $get_related_robots = toolset_get_related_posts( $current_post_id, 'jugado', 'parent', 99999, 0, array(), 'post_id', 'child' );
              
            if(!empty($get_related_robots)) {
                $query->set( 'post__in', $get_related_robots );
            }else{
               $query->set( 'post__in', array(0));
            }
                 
                 
            }
        }       
    }
}
add_action( 'pre_get_posts', 'func_filter_parent_relationship_dropdown_select2', 99, 1 );

Where:
- We used the post relationship API function "toolset_get_related_posts" to get the current post related number copuons.

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts