I have a custom post type called 'profiles' and another called 'alerts'.
'Profiles is' the parent of 'Alerts'.
On the CRED form for Alerts I am trying to autofill the value for _wpcf_belongs_profile_id to be the ID of the 'Profile' post with the same author as the logged in user. (Users will only have one profile).
I have tried the following in functions.php:
function return_alert_parent() {
$user = wp_get_current_user();
$result = new WP_Query(array(
'author' => $user->ID,
'post-type' => 'profile',
));
if (empty($result)) { return (0);}
else {return $result[0]->ID;}
}
add_shortcode ('alert_parent', 'return_alert_parent');
My CRED form looks like this:
<div class="form-group">
<label>profile Parent</label>
[cred_field field='_wpcf_belongs_profile_id' value='[alert_parent]' select_text='--- not set ---' class='form-control' output='bootstrap']
</div>
When I go to the page (hidden link) I just see a blank page. I do have a existing profile for the logged in user. I have registered the shortcode as a third party argument. Before I registered the shortcode I was seeing the form, but the value wasn't filled in. After I registered the shortcode I just get a blank page.
Can you see what I'm doing wrong?