Tell us what you are trying to do?
I have a post type "bb" with a Post Form for front end users. At the end of the form the user can select to "Add a room" Repeatable Form Group form. The Add Room Form has the parent select dropdown. I want to avoid showing that to the user and have the parent be automatically filled and hidden.
Is there any documentation that you are following?
I've followed this: https://toolset.com/forums/topic/current-user-posts-in-child-posts/
I can't seem to get it to work.
Here is the pertinent part of the shortcode for the child post form - "bb" is the parent CPT:
<input type="hidden" id="parents_id" value="[get-parents]" />
[cred_field field='_wpcf_belongs_bb_id' value='' select_text='--- not set ---' class='form-control' output='bootstrap']
[cred_field field="@add-room-field.parent" class="form-control" output="bootstrap" select_text="--- not set ---"]
</div>
[cred_field field="form_submit" output="bootstrap" value="Submit" class="btn btn-primary btn-lg"]
[/credform]
Here is the JS code in that form:
jQuery('document').ready(function(){
var post_parents = jQuery('#parents_id').val();
var arr = post_parents.split(',');
jQuery("[name=_wpcf_belongs_bb_id] > option").each(function() {
var option_val = jQuery(this).val();
if( jQuery.inArray(option_val, arr) == -1 && option_val != -1 ){
jQuery(this).remove();
}
});
});
And here is the functions.php code I've used via the Code Snippets plugin:
function get_parents($atts) {
global $current_user;
get_currentuserinfo();
$author_query = array('post_type' => 'bb', 'posts_per_page' => '-1','author' => $current_user->ID,);
$author_posts = new WP_Query($author_query);
$parent_ids = "";
while($author_posts->have_posts()) : $author_posts->the_post();
$parent_ids .= get_the_ID() .",";
endwhile;
return $parent_ids;
}
add_shortcode('get-parents', 'get_parents');
I've also read this:
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected
This seems to require that the form be embed on the frontend parent post - that will not work for me.
What is the link to your site?
hidden link
Thanks for your help.
Wayne