Skip Navigation

[Resolved] retrieve field from a related post in post wordpress admin

This support ticket is created 2 years, 11 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
- 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 11 replies, has 3 voices.

Last updated by davidS-72 2 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2288853
Captura de pantalla 2022-02-10 175047.jpg

Tell us what you are trying to do?
retrieve the content from a WYSIWYG field of a related post(1 capture) and put the retrieved content in a field of a new post(2 capture).

Is there any documentation that you are following?
nop, I didn't found information

Is there a similar example that we can see?
Fill a WYSIWYG field with a data from a field from a related post, selected with a dropdown.

What is the link to your site?

#2288927

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for getting in touch.

Is it that you want to retrieve the value that is stored in a separate post completely?

If so then this won't be possible to do unless you use some custom code to achieve.

Unfortunately the custom code that is required to do this is out of the scope of our support forum.

Thanks,
Shane

#2289389

I'll try to explain me better:
When I edit a post type A, there are a field to select a refered post (type B). Then, I want to copy the content of a field from the selected refered post to put this content in a field of the post I'm editing.

best regards,
David

#2289661

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for the clarity however any copying of field data from another post into your current post will require custom code to achieve or you manually copy and paste the data in.

As mentioned the custom code required for this would be out of the scope of our support forum as we will first need to retrieve the post that was selected and then insert that data into the post being edited and that will need to be done once an action is triggered on the post edit screen such as the when the post is created or when the update button is clicked.

Thanks,
Shane

#2290301

Hi Shane,
I undertand. Then, to find an alternative solution to my problem: Is there some way to retrieve the related post's URL, one time the update button has been clicked to save the related post selected? My intention is put a link to the related post to facilitate the copy of data.

thanks
David

#2291767

Minesh
Supporter

Languages: English (English )

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

Hi David,

Shane is on vacation. This is Minesh here and I'll take care of this ticket. Hope this is ok.

Can you please tell me you want to copy the content while you edit the post in backend?
If yes, there is no such feature exists and it will require custom programming that is beyond the scope of our support policy. If you wan custom programming for your project you are welcome to contact our certified partners:
- https://toolset.com/contractors/

#2291775

Hi Minesh,
I'm looking for an alternative solution.
Instead copy content from a related post, a solution could be put the link to the related post, to wordpress admin or single page, in the edit post page and the user will copy manually the content.

How can I do that?

thanks,
David

#2291923

Minesh
Supporter

Languages: English (English )

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

I'm still not clear where you want to allow users to copy the things.

If you want to connect the post of post type A with post type B, you can use and setup the post reference field. So when you edit the post of post type A, it will allow you to link the post of post type B.
- https://toolset.com/course-lesson/using-post-reference-field-to-set-up-one-to-many-relationships/

Do you want this or you still have other ideas, if thats the case, can you please explain the whole flow user will have to follow from start to end to copy your content. Do you want to allow user to copy content from backend or using Toolset form?

#2297633
Captura de pantalla 2022-02-19 212253.jpg

Hi Minesh,
I want when a user is editing a post, like shown at attached screenshot, and select a post reference (1 in screenshot) , the field WYSIWYG (2 in screenshot) is filled with the content from a WYSIWYG field from referenced post in 1.

thanks,
David

#2298387

Minesh
Supporter

Languages: English (English )

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

Ok, your requirement is clear but there is no such feature exists as of now to copy the post content to another field on select of post reference field option.

But the only workaround would be is we may have option to copy the content of filed 1 to field 2 when you save the post. If that is ok for you, then you can use the save_post action hook.
=> https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/

What you can do is, you can use the save_post hook and based on the post reference field value, you can get the ID of post and get the content of the post that is saved with post reference field and then copy the content to your desired field.

Please let me know if you require any help with that and for that please share admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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 have set the next reply to private which means only you and I have access to it.

#2299693

Minesh
Supporter

Languages: English (English )

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

I've added the following save_post hook to "Custom Code" section offered by Toolset:
=> hidden link

function func_save_custom_field_value( $post_id, $post, $update  ) {
    if ( 'cpt2' == $post->post_type  ) {
        $parent = toolset_get_related_post($post_id,'cpt1-referenced');
        $parent_desc = get_post_meta($parent, 'wpcf-description-origin-s-data-to-copy-to-cpt2', true);
        update_post_meta($post_id, 'wpcf-content-2', $parent_desc);
      }
}
add_action('save_post', 'func_save_custom_field_value', 99, 3 );

I've created the following post and I can see the parent custom post field value is copy successfully to the new post:
=> hidden link

Important Note:
- Please note that you will have to use classic editor to add/edit posts for post type "cpt2" as with block editor will not work as expected.

#2299985

My issue is resolved now. Thank you!