Skip Navigation

[Resolved] Autofill parent value with id of parent post with logged in user as author

This support ticket is created 6 years, 6 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.

This topic contains 1 reply, has 1 voice.

Last updated by gavinS-2 6 years, 6 months ago.

Author
Posts
#914636

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?

#914655

Don't worry about this. I found another solution.