Skip Navigation

[Resuelto] Setting up post relationship with form not made with cred

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
How to make relationship with parent post using CRED form from child form.

Solution:
When using Types posts relationships, the parent of a given type is stored in a postmeta table with key name equal to: _wpcf_belongs_{parent-post-slug}_id

Where:
Replace {parent-post-slug} with your parent post type slug value.

You can find proposed solution with the following reply:
https://toolset.com/forums/topic/setting-up-post-relationship-with-form-not-made-with-cred/#post-394098

Relevant Documentation:

This support ticket is created hace 6 años, 9 meses. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 respuestas, has 2 mensajes.

Last updated by mirjanaM hace 6 años, 8 meses.

Assigned support staff: Minesh.

Autor
Mensajes
#393962

Hi,
to explain a bit....

I use all from Toolset, but for a specific form i used Formidable Pro. Now i have a problem how i can make the connection with the Parent Post type. So that the parent of this post is Auto selectet.

---------

Parent Posttype
- Event (slug:event)

Child Posttype of Event
- Reviews (slug:reviews)

--------

What i have tryed is to put the Formidable Pro Form in an CRED Post Forms.

 
[cred_generic_field field='post_title' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"generic_type":"post_title",
"default":"[wpv-post-title id="$event"]"
}
[/cred_generic_field]


[display-frm-data filter=1 id=95]

<div class="hidden">
   
	<div class="cred-group cred-group-parents">
		<div class="cred-field cred-field-_wpcf_belongs_event_id">
			<label class="cred-label">
		Event Parent
		</label>
			[cred_field field='_wpcf_belongs_event_id' value='']
		</div>
		
	</div>

[/credform]

and in functions.php

add_action('cred_save_data', 'review_action',10,2);
function review_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==25)
    {
        //get the Post ID of the current event:
       $event_id = $form_data['container_id'];
       //update the new review post parent field with this ID:
       update_post_meta($post_id, '_wpcf_belongs_event_id', $event_id);
    }
}

Hope anyone can help me.

mira

#394098

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

When using Types posts relationships, the parent of a given type is stored in a field:

 _wpcf_belongs_{parent-post-slug}_id

Let’s assume that we are displaying a Car post type that has a Maker as a parent post type.
Each Car will store its Maker (parent) id in the field _wpcf_belongs_maker_id.

So what you need to do is - Using whatever form you create entry you need to make sure that following code should be run in order to make relationship between your chiild and parent post:

update_post_meta($post_id, '_wpcf_belongs_event_id', $event_id);
#394348

Hi Minesh,

i have tryd the code from above and this all but no change. Still i must select the parent.
Hope you have another idea.

add_filter('formidable_register_url', 'formidable_url', 10, 3);
function formidable_url($entry_id, $form_id, $post_id) {

if ($form_id == 6) { // The Formidable Form ID
    $event_id = $form_id['container_id'];
    update_post_meta($post_id, '_wpcf_belongs_event_id', $event_id); //Update parent Post
  }
  return $errors;
}
 
add_filter('frm_update_entry', 'update_parent_validation', 8, 3);
function update_parent_validation($errors, $posted_field, $posted_value, $post_id, $form_data){
  $field_id = 82; // The Formidable Form Field ID
  if ( isset( $_POST['item_meta'][ $field_id ] ) ) {
    $field_value = sanitize_text_field( $_POST['item_meta'][ $field_id ] );
       $event_id = $form_data['container_id'];
    update_post_meta($post_id, '_wpcf_belongs_event_id', $event_id); //Update parent Post
  }
  return $errors;
}
#394454

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

1)
Could you please share problem URL where you have added your CRED form? Also, please explain me how you are getting your parent ID?

2)
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#400764

Thank you Minesh it works 😉