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
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"
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]
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
My issue is resolved now. Thank you!