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.
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?
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]);
}
}
}
}
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?
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');
}
}
}
}
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.