Skip Navigation

[Resolved] Set post relationship using cred_save_data

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

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Benjamin 5 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1203854

I am trying to create a child post by just a button from the cred form and set the post_name, post_title and @post_to_post.parent.

post_name and post_title are updating just fine, but i can't set @post-to-post.parent.

the code i'm using:

add_action('cred_save_data', 'biz_set_title',10,2);
function biz_set_title($post_id, $form_data){

if ($form_data['id']==162){

$post = get_post( $post );
$title = isset( $post->post_title ) ? $post->post_title : '';
$id = isset( $post->ID ) ? $post->ID : 0;
wp_update_post(array('ID' => $post_id, 'post_title' => $title,'post_name' => $id));
update_post_meta( $post_id, '@post-to-post.parent' , $id);
}
}

the form is placed in a view loop.

Please help me figure this out. 🙂

Thanks Ben

#1204239

Hello,

In your case, you don't need to setup the custom codes, you can put the relationship field into the post form, and use CSS codes to hide them, after user click the submit button, Toolset form will be able to setup the post type relationship for you.

See our document:
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected

Section "Creating forms when a parent post is preselected"

#1204286

Hello Luo Yang,

unfortunately I have to. I want to display the button/cred form directly on a parent view and don't want to change the page with a cred_child_link_form.
My goal is to create an intermedite post for a follow function. A subscriber shall be able to follow and unfollow a "blog-post".

My plan:

User (role = subscriber) is the author of a follow-post.
The follow-post is a child post of a blog-post.
The author of the blog-post is another User (role = customer).

With this intermedite post I'll be able to create a view on the subscribers "My-Site" with all the blog-posts he is following.
I did the "function" like this:

View which is displayed on the blog-post, with the filters

  • follow-post is related to blog-post where this view is shown
  • Author is current logged in user
[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          
          	[cred_delete_post_link action='delete' text='unfollow' message_show='0' class='ui primary fluid button cred-refresh-after-delete']
          
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		
		[cred_form form="follow-form"]

	[/wpv-no-items-found]
[wpv-layout-end]

This is the CRED-form:

[credform]
    <div class="form-group hide"> 	
	[cred_field field='@follow-blog.parent' class='form-control' output='bootstrap' select_text='--- not set ---' readonly='true']
	</div>
	[cred_field field="form_submit" value="Follow" class="ui primary fluid button"]
[/credform]
#1204368

Thanks for the details, I assume we are talking about a post form "follow-form" for creating child "follow-post" post.

You just need to setup the default value of relationship field as current "blog-post" post, for example, edit the post form "follow-form", replace this line from:

[cred_field field='@follow-blog.parent' class='form-control' output='bootstrap' select_text='--- not set ---' readonly='true']

To:

[cred_field field='@follow-blog.parent' class='form-control' output='bootstrap' select_text='--- not set ---' readonly='true' value='[wpv-post-id id="$current_page"]']

And test again.

More help:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
value. Optional. Preset value

#1204405

My issue is resolved now. Thank you!