‘post_type’ => ‘nf_sub’,
‘user_id’ => get_current_user_id(),
);
// wp_eMember_get_user_details(“user_name”)
$subs = Ninja_Forms()->subs()->get($args);
$data[‘list’][‘options’] = array();
foreach ($subs as $sub) {
$form_id = $sub->form_id;
$user_id = $sub->user_id;
$data[‘list’][‘options’][] = array(
‘label’ => $sub->get_field(62),
‘value’ => $sub->get_field(62),
‘calc’ => null,
‘selected’ => 0
);
}
}
// Query call submissions and Fill in Text Box
if ($data[‘label’] == ‘Inbound Calls’) {
$args = array(
‘form_id’ => 10,
‘post_type’ => ‘nf_sub’,
‘user_id’ => get_current_user_id(),
‘Call Direction’ => ‘Inbound’,
‘Date’ => ‘Date’,
);
$query1 = new WP_Query($args);
$myfound = $query1->found_posts;
$data[‘default_value’] = “Inbound Calls: {$myfound}”;
}
if ($data[‘label’] == ‘Outbound Calls’) {
$args = array(
‘form_id’ => 10,
‘post_type’ => ‘nf_sub’,
‘user_id’ => get_current_user_id(),
‘meta_query’ => array(
‘key’ => ‘Call Direction’,
‘value’ => ‘Outbound’,
‘compare’ => ‘=’
),
);
$query1 = new WP_Query($args);
$myfound = $query1->found_posts;
$data[‘default_value’] = “Outbound Calls: {$myfound}”;
}
if ($data[‘label’] == ‘Total Calls’) {
$args = array(
‘form_id’ => 10,
‘post_type’ => ‘nf_sub’,
‘user_id’ => get_current_user_id(),
);
$query1 = new WP_Query($args);
$myfound = $query1->found_posts;
$data[‘default_value’] = “Total Calls: {$myfound}”;
}
wp_reset_postdata();
/* New code*/
$args = array(
‘form_id’ => 10,
‘post_type’ => ‘nf_sub’,
‘user_id’ => get_current_user_id(),
);
$subs = Ninja_Forms()->subs()->get($args);
$inbound = 0;
$outbound = 0;
foreach ($subs as $sub) {
if ($sub->get_field(19) == ‘Inbound’) {
$inbound++;
} elseif ($sub->get_field(19) == ‘Outbound’) {
$outbound++;
}
}
$total = $inbound + $outbound;
if ($data[‘label’] == ‘Outbound Calls’) {
$data[‘default_value’] = “Outbound Calls: {$outbound}”;
}
if ($data[‘label’] == ‘Inbound Calls’) {
$data[‘default_value’] = “Inbound Calls: {$inbound}”;
}
if ($data[‘label’] == ‘Total Calls’) {
$data[‘default_value’] = “Total Calls: {$total}”;
}
return $data;
}
add_filter(‘ninja_forms_field’, ‘my_prepopulate_forms’);
?>