Skip Navigation

[Resolved] Access for Editors to categorized CPTs only

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 Minesh 9 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2685765

Hi there,

i have to create a role or mutiple roles for editors that only have access to "grouped posts".
This has to happen dynamically... so my idea was to categorize my CPTs that are created via credform frontend with a connection to a toolset maps address field. This adress field should referf to a give taxonomy. I need to group my backend-access to areas and only "area managers" should have access to their posts. I thought i could use the access post group feature but I don't see how.

Kind regardas, Alex

#2685892

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Toolset stores the assigned "Post Group" value to the post meta key "_wpcf_access_group" in the postmeta database table.

To assign the access post group dynamically based on the taxonomy term - you will have to use Toolset form's hook "cred_save_data":

Please check the following ticket that might help you:
- https://toolset.com/forums/topic/split-dynamic-post-groups-based-on-field-or-taxonomy-values/
- https://toolset.com/forums/topic/let-the-author-decide-whether-a-post-is-publicly-accessible-or-only-for-members/

#2685902

Thx for your reply... so if i understand right... something like this could work? i create taxonomy-terms that are assigend to metavalues... if the the taxonomy is assigned it updates or creates the meta-value, right?

add_action('cred_save_data', 'my_save_data_action', 10, 2);

function my_save_data_action($post_id, $form_data) {
// Check if the form ID matches the form you're targeting
if ($form_data['id'] == 12345) {
// Check if the current user has selected a specific term from the "postleitzahlenbereich" category
if (isset($_POST['tax_input']['postleitzahlenbereich'])) {
$selected_term = $_POST['tax_input']['postleitzahlenbereich'];

// Define an array to map terms to post group meta values
$term_to_group_mapping = array(
'plz1' => 'group-value-for-plz1',
'plz2' => 'group-value-for-plz2',
// Add more terms and their corresponding group values here
);

// Check if the selected term exists in the mapping array
if (array_key_exists($selected_term, $term_to_group_mapping)) {
// Update the post meta with the corresponding group value
update_post_meta($post_id, '_wpcf_access_group', $term_to_group_mapping[$selected_term]);
}
}
}
}

#2685903

Just an idea... i only thought about using taxonomy and terms as vehicle. Could i also just assign a post directly to a post group if a custom field value (in my case postal code) is in a specific numeric range like so?

add_action('cred_save_data', 'my_save_data_action', 10, 2);

function my_save_data_action($post_id, $form_data) {
// Check if the form ID matches the form you're targeting
if ($form_data['id'] == 12345) {
// Get the value of your custom field
$custom_field_value = isset($_POST['my_custom_field_name']) ? $_POST['my_custom_field_name'] : '';

// Check if the custom field value is a number
if (is_numeric($custom_field_value)) {
// Convert the custom field value to an integer
$custom_field_value = intval($custom_field_value);

// Define your range of 5-digit numbers
$start_number = 10000; // Change this to your desired start number
$end_number = 99999; // Change this to your desired end number

// Check if the custom field value falls within the range
if ($custom_field_value >= $start_number && $custom_field_value <= $end_number) {
// Update the post meta with the corresponding group value
update_post_meta($post_id, '_wpcf_access_group', 'your_desired_group_value');
}
}
}
}

#2685906

Minesh
Supporter

Languages: English (English )

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

Yes - it could work but you will have to test with real-life example and data.

Where how you will get the distance range from the custom field? what is your center point for that range to apply? You will have to get that sort out and it should work probably with little or more changes required as per your requirement.