Added the "output=raw" to the code. Since the edit link on the page hidden link has disappeared, so I cannot see if its working or not. So I tried with the page "Aggiungi Opportunità Imprese" which is the page with the cred that adds a new job opportunity. Still not working. And I don't quite understand what you mean when you say "please move the View outside of the generic field so you can observe the results generated by the View".
If you could, I would be grateful if you tried to add or edit an opportunity on the front-end and then check on the back end if the association has been done correctly. If you could log in and take a look yourself It would be great because it seems ok on my end, but still... it's not working, and I REALLY need this to work. I am so grateful you're being so helpful and I am sorry to bother you so much but this is very very important for me.
I think I figured out what you asked: here it is
{"value":"178","label":"SATA SERVIZIO ASSISTENZA TECNICA ARTIGIANI"} ,{"value":"140","label":"CEDIT - CENTRO DIFFUSIONE IMPRENDITORIALE DELLA TOSCANA"} ,{"value":"141","label":"I BORGHI SRL"} ,{"value":"142","label":"IANNELLI SRL"} ,{"value":"143","label":"NESTI SAS DI LETIZIA E SABRINA NESTI & C."} ,{"value":"144","label":"TIPOGRAFIA LA MODERNA SRL"} ,{"value":"145","label":"DATAFOX SRL"} ,{"value":"115","label":"ROSSI & RICCERI SNC"}
I'm not sure why the edit link isn't showing up. I will take a closer look at that. For now, to test editing a post you can use the URL format hidden link
Just change the opim-243 part to use the correct post slug. This should show the form so you can run tests.
It looks like the generic field generated by the view you told me to create is not storing any value in the wpcf_belongs_impresa_id.
That's correct, we have not added this part yet. You must add a cred_save_data hook to accomplish this, but let's not get ahead of ourselves. We need to determine why the Edit Link stopped appearing. I will take a look and get back to you shortly.
It looks like the CRED form was changed to edit "Articoli" instead of the Opportunita Imprese CPT. This is why the "Modifica" links were not appearing. I changed that and now the links are back. So please check it out and let me know if you're ready to move to the next step, which is saving the parent post reference when the CRED form is submitted.
Ok, now the edit link is back. Thanks.
I am ready to get to the next step. One question: are these steps valid for both the edit and the add child posts?
These steps apply to both adding and editing child posts, and there is one extra step in the Edit Post CRED form that selects the appropriate parent post when the page loads. I can share that later. Here is the code that will save the parent post connection:
add_action('cred_save_data', 'cred_belongs_impresa_action',10,2);
function cred_belongs_impresa_action($post_id, $form_data)
{
$forms = array( 196, 9999 );
// if a specific form
if (in_array($form_data['id'], $forms))
{
if (isset($_POST['selectcompany']))
{
update_post_meta( $post_id, '_wpcf_belongs_impresa_id', $_POST['selectcompany'] );
}
}
}
Try this out and let me know if the parent impresa post is saved correctly.
As you can see it doesn't seem to work. I added it as you wrote it. Do I have to change anything?
It just worked for me on this post:
hidden link
I can now see the parent here:
hidden link
Can you tell me which post you were editing?
Which parent post did you select?
Can you provide the login credentials for your User in the private reply fields here?
Okay you were adding a child post, not editing a child post, correct? That's a different CRED form. We didn't finish the changes necessary for adding posts yet, I was testing the edit form. For the "add" child post CRED form to work, you need to modify this line of code in functions.php:
$forms = array( 196, 9999 );
You must replace 9999 with the numeric ID of the CRED form that adds child posts. Please try that and let me know if the Add post CRED form works as expected.
Chris, it worked perfectly. I then re-edited functions.php and put it back the way it was. Ready for the next step. THANK YOU!!!
I think the next step is to update the default value of the generic field in the Edit CRED form. This will select the correct parent post by default when the page loads.
"default":[[wpv-post-id id="$impresa"]],
It's working beautifully!! Thank you so much for your precious help!
So the editing of the child posts is up and running.
Now I have to duplicate the same process for the NEW child posts. How do I go about it?
There's nothing special to do on the Add post CRED form. The code in the CRED form builder can be exactly the same as the edit form except the generic field default attribute should be:
This means the generic field will not have anything selected when the page loads. The cred_save_data code was already modified to support both forms, so the parent Impresa post should be saved as expected when the form is submitted. I think you should run several tests now. Creating new posts and edit those posts while logged in as different Users. Verify the parent post options list is accurately filtered, and verify the parent post is saved correctly each time in wp-admin.
I tried adding a new child post but the company wasn't saved. Is the function you had me add to functions.php the same for both? Shouldn't I be adding a similar function for the adding process? The cred form ids are different. In fact you had me change the 9999 to the add post cred form id, in the previous post.
add_action('cred_save_data', 'cred_belongs_impresa_action',10,2);
function cred_belongs_impresa_action($post_id, $form_data)
{
$forms = array( 196, 9999 );
// if a specific form
if (in_array($form_data['id'], $forms))
{
if (isset($_POST['selectcompany']))
{
update_post_meta( $post_id, '_wpcf_belongs_impresa_id', $_POST['selectcompany'] );
}
}
}
I changed 9999 to 230, which is the id of the edit cred form, so I thought that for the adding process, there would be a similar function with different parameters...
I guess I figured it out for myself: I changed the parameters from this :
$forms = array( 196, 9999 );
to this:
$forms = array( 196, 230);
and now it seems to be working.
Can I please leave the ticket open while I perform tests? I would like to close it when I am sure everything is working.