Skip Navigation

[Resolved] limit parent drop down by author

This thread is resolved. Here is a description of the problem and solution.

Problem:
limit parent drop down by author on Toolset child form with parent field

Solution:
You can use the attribute author="$current" so that the select dropdown only includes parent posts authored by the current user for your parent dropdown select.

Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

This support ticket is created 5 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)

This topic contains 4 replies, has 2 voices.

Last updated by MattI4840 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1222437

I am trying to: I have a one to many relationship set up between two cpts 'clients' and 'estimates'. There is a drop down to select the client on the post form that allows you to create new estimates. Currently it displays all clients, I need it to only display clients that were authored by the logged in user.

Link to a page where the issue can be seen:

hidden link

I found this support thread which directly address the topic:

https://toolset.com/forums/topic/parent-dropdown-must-only-show-parents-created-by-the-current-user/

However when I attempt to utilize the code supplied via custom code snippet it isn't working. Here is the code I'm using.


add_filter('wpml_cred_potential_parents_filter', 'my_func', 10, 4);
 
function my_func($parents, $wpml_name, $wpml_context, $args){
    global $wp_query;
    $current_user_id = get_current_user_id();
    $cred_form_ids = array(529, 589);  // here setup the specific CRED form IDs
    $arr = explode('-', $wpml_context);
    $end = end($arr);
    if($wpml_name == '_wpcf_belongs_client-estimate_id' && $current_user_id && in_array($end, $cred_form_ids)){
        $args['author'] = $current_user_id;
        $parents = get_posts($args);
    }
    return $parents;
}

#1222847

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - You can use the attribute author="$current" so that the select dropdown only includes parent posts authored by the current user for your parent dropdown select.

I've added the attribute as given under:

[cred_field field='@client-estimate.parent' class='form-control' output='bootstrap' author="$current" select_text='--- not set ---']

Can you please confirm it works for you as expected.

#1223074

Minesh,

That works perfectly, would you just let me know where I can find that in the documentation, then we can mark this resolved.

Thanks,
Matt

#1223712

Minesh
Supporter

Languages: English (English )

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

Yes - sure. Here is the Doc:
=> https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

author Optional. Use it with a parent selector field to specify that the list of parent posts should be limited to those authored by the mentioned user ID. The value $current can be used to define that the current user should only see their own parent posts in a dropdown.
#1223935

My issue is resolved now. Thank you!