Skip Navigation

[Resolved] Using fields from one post type in view to fill CRED fields for other post type

This support ticket is created 6 years, 9 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.

Our next available supporter will start replying to tickets in about 2.15 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Noman 6 years, 9 months ago.

Assisted by: Noman.

Author
Posts
#614150

Tell us what you are trying to do?

I have two post types, (request-line and accessories), which both have the same parent post type (item-model).

request-line has the field 'quantity' as well as the parent item-model.

accessory has the fields 'amount' & 'accessory-item' as well as the parent item-model.

The field 'accessory-item' is actually storing item-model id's as well as the parent item-model id. The reason for this is that I'm trying to store a list of items that are accessories for the parent item. eg. If you rent a certain item, I want to suggest a list of other items that people normally rent with the original item, for the user to accept or edit.

When a request-line form is submitted, I would like to query accessories to see if there are any that have the same parent model-item as the request-line just submitted.

If there are matches I would like to open a view on a new page which shows a list of CRED forms, one for each accessory that has the same parent, HOWEVER, the forms should be saving to request-line, not accessory.

So If there are three accessories that have the same parent model-item as the current request-line, I wish to show a view with three request-line CRED forms, with the 'amount' and 'accessory-item' fields from the three corresponding accessories filled in as default values for the 'quantity' and 'model-item' parent fields for the request line forms.

So then the user can edit or submit those 3 forms, and then go back to the page where they were filling in the request-lines.

Does this make sense? How could I go about doing this?

#614257

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Gavin,

Thank you for contacting Toolset support.

request-line has the field 'quantity' as well as the parent item-model.
>> Not getting this point, does it mean that “Quantity” field is present in both CPTs request-line and Parent CPT item-model?

The field 'accessory-item' is actually storing item-model id's as well as the parent item-model id.
>> What does the last “parent item-model id” mean? As you have said that the field 'accessory-item' is actually storing item-model id's.

Please provide temporary access WP-Admin Login and FTP login info to your site. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the related back-end links.

Thank you

#614624

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Gavin,

You can achieve it by doing following steps:

- When user submit request-line CRED form then we can redirect user to specific page using following hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete
hidden link
with parent id in URL i.e your-site.com/cred-page?parent_id=XX

- On that page we need to get all accessory posts that accessory-item field have same value as request-line parent in parent_id parameter. We can use following class:
https://codex.wordpress.org/Class_Reference/WP_Query
hidden link

- Now we need to display same number of CRED forms for request-line CPT as we have total matched accessory posts in previous step.

- To pre filled quantity and parent field in CRED forms we need to make small shortcode and we can use following docs to achieve it:
https://developer.wordpress.org/reference/functions/get_post_meta/
https://codex.wordpress.org/Shortcode_API
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Please note this requires a custom code or modifications which falls into Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/). So we recommend to contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

Thank you