Skip Navigation

[Resolved] I wish to pull the data from a custom post into a different custom post.

This support ticket is created 5 years, 5 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 12 replies, has 2 voices.

Last updated by grahamA 5 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1291819

Tell us what you are trying to do?
I have a custom post type called “presets” and another custom post type called “printers”
‘Printers’ has many fields but also shares the same fields that ‘presets’ has. Is it possible to show and include the data fields from ‘presets’ in printers when a new ‘printers’ posts is created?

Is there any documentation that you are following?
I have become very confused in relationships and relationship forms so I hope you can tell me if this is possible.
Is there a similar example that we can see?
No
What is the link to your site?

#1291957

Shane
Supporter

Languages: English (English )

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

Hi Graham,

Thank you for contacting our support forum.

Are you referring to just having the fields themselves or do you want the data to be included as well ?

Please let me know.
Thanks,
Shane

#1291985

Hi Shane

I need the fields and field values. I plan to have 3 Printer post types ie Printer 1, Printer 2, Printer 3. Each has unique fields but when creating a new post from each i will pull the fields and values from post 'presets A' a single post created from post type 'presets'

For clarity, the end result will be post Printer 1A, Printer 1B, Printer1C, etc will pull values and fields from post 'presetA'
Post Printer 2A, Printer 2B, Printer2C etc will pull values and fields from post 'presetB'

Bit confusing I appreciate but I hope that explains.

Thanks

#1292113

Shane
Supporter

Languages: English (English )

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

Hi Graham,

Thank you for the explanation, I believe it is best to use a post relationship here. Are the presets tied to only 1 printer ? or can the presets be assigned to Printer 1 and printer 2?

Please let me know and we can go from there.

Thanks,
Shane

#1292573

Hi Shane

Presets can be assigned to post type Printer 1 and post type printer 2 and there will be other post type printers too using the same presets in the final usage.

Thanks

#1292945

Shane
Supporter

Languages: English (English )

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

Hi Graham,

So this seems to me like a many to many relationship. Where printer A can have many different presets and presets can be assigned to many different printers.

Will you be the one setting up the presets to the printers or do you want this to be done through the frontend?

Please let me know as using the relationship is the best approach and you can just pull the information from the various posts on another post.

Thanks,
Shane

#1292957

Hi Shane

I will setup the presets in the backend as a post type however the actual posts from it will be updated in the front end by users.

My understanding of relationships was that of child and parent posts ie linking between each and not pulling data. The magic bit you say "you can just pull the information from the various posts on another post" is exactly what I wanted but cannot see how you take data from a post in order to include it in another. I look forward to your tutorial on this. I do hope it is not a repetition of the album and songs tutorial as that is where I have got lost 🙂

#1292961

Shane
Supporter

Languages: English (English )

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

Hi Graham,

Technically you are not pulling the data from another post to store it in another. Its like this, because a printer and a preset are related then you can pull printer A and all of its related presets data onto a page.

So in your case a use will create a document A, then have the option to select Printer A or Printer B, then also select preset A or B correct?

I would like to know the entire scope since now it seems there are 3 Post types involved.

Thanks,
Shane

#1292979
relationship_diag.jpg

Hi Shane

I hope the attached diagram explains things better. It can get confusing.

Thanks

Graham

#1293065

Shane
Supporter

Languages: English (English )

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

Hi Graham,

I see now. So each printer is created as a post Type. So a user will create a document in either printer lets say A. Then they can choose a preset from the preset CPT to assign to the document that was created in a Printer?

This sounds more like what you want to achieve.

Thanks,
Shane

#1293507

Hi Shane
Almost there,
I want to be able to set the Printer 1 UK, Printer 2 UK posts to always use the Preset A UK data.
In the same way set the Printer 1 USA, Printer 2 USA posts to always use the Preset B USA data . I may have confused you here and should have called the presets just Preset UK and Preset USA etc.

The scenario is I set up posts from Printer 1 and 2 in the back end calling them UK,USA,DE,FR,SP for each printer type etc for all countries. I can manually edit those posts in the backend to link to the correct Preset country post. The reason the presets need to be as a separate post for each country is that a frontend manager will need to edit the values through a credform for their own country.

We have custom code that then allows a user to clone a printer post (like a template) of their own country and save it as a new post.

Please show me how to pull data from one post into another rather than just setting up post child parent links.

Thanks
Graham

#1294097

Shane
Supporter

Languages: English (English )

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

Hi Graham,

I want to be able to set the Printer 1 UK, Printer 2 UK posts to always use the Preset A UK data.
In the same way set the Printer 1 USA, Printer 2 USA posts to always use the Preset B USA data . I may have confused you here and should have called the presets just Preset UK and Preset USA etc.

Actually you wont be able to set a default preset, unless the preset is a custom field on the printer itself. So the customer will need to select from the list of presets the one they want to use.

You can pull the data from the field of another cpt to store it into this one using custom code but you will need to know the ID of the preset that you want to use.

So with this function below you are able to pull data from another post.
https://developer.wordpress.org/reference/functions/get_post_meta/

This can get a little bit confusing because with the copying and pasting of the data from the presets it will cause duplication of data.

Thanks,
Shane

#1297651

My issue is resolved now. Thank you!