Accueil › Toolset Professional Support › [Résolu] Connecting Two CPT’s with intermediary CPT via CRED Edit Form
Problem:
Connecting Two CPT's with intermediary CPT via CRED Edit Form
Solution:
You can use CRED hook "cred_save_data" to do any customization you
need and to connect the post using intermediary post entry.
You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/using-user-account-to-connect-member-profiles-with-articles-via-intermediary-cpt/#post-815355
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
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)
Ce sujet contient 16 réponses, a 2 voix.
Dernière mise à jour par Ronald E Il y a 6 années et 6 mois.
Assisté par: Minesh.
I have 3 CPT (Custom Post Types)
Parents: Member Profile, Article
Child: writer
I have user accounts with memberships using Access and content entry via Cred Post Forms and Types content templates (some modified with BB Page Builder). I've got it setup so a user will login via a User Form. They then can Add New Articles or Edit an existing article.
All that works great. What I want to be able to do is allow the user, via a Cred Form, Assign a Member Profile to the article they write. I can do it in the WordPress Admin (see screenshot
member-profile-assigned-to-article.gif ). How can I set it up so the user, who is logged into the front-end created by Access, be able to do it with a Cred Form while they are creating their article?
Sequence in screenshots below
1. toolset-login-screen - user logs in
2. toolset-list-of-articles - user goes to his list of articles and clicks on "Make Edits"
3. toolset-editing-article - user can make edits to his article. this is where I'd like them to be able to select their Member Profile (Not user account) and associate it with their article they are editing
4. toolset-live-article-with-member-profile-displaying - this will be how the member profile will look under their article.
thank you for your help,
Ronald E
Hello. Thank you for contacting the Toolset support.
Well - I would like to know here , have you added the member profile field to articles CRED Edit form? If no:
As I understand - you want to display all the member profile as select box with article CRED edit form and allow user to select the specific member profile and set the selected member profile as parent of currently editing article?
Additionally - Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/
Hi Minesh,
"Well - I would like to know here , have you added the member profile field to articles CRED Edit form? If no: "
I tried. It does not show up in the list to "Add Post Fields" (see attached image).
"As I understand - you want to display all the member profile as select box with article CRED edit form and allow user to select the specific member profile and set the selected member profile as parent of currently editing article?"
Yes, I want the user to be able to select his name from the Member Profiles so it shows up relationally to the AAIMCo article he wrote.
Please let me know if you need admin login to the website or anything else
thank you,
Ronald E
Yes - could you please share problem URL where you want to display the CRED form as well as what information you want to display with member profile select field.
*** 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.
I've created a view that lists member profiles and output as JSON format:
=> lien caché
I've also added following code to your current theme's functions.php file - which helps to raw output of above view:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 ); function prefix_clean_view_output( $out, $id ) { if ( $id == '3679' ) { $start = strpos( $out, '<!-- wpv-loop-start -->' ); if ( $start !== false && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false ) { $start = $start + strlen( '<!-- wpv-loop-start -->' ); $out = substr( $out , $start ); $end = strrpos( $out, '<!-- wpv-loop-end -->' ); $out = substr( $out, 0, $end ); } } return $out; }
I've added following code to CRED form - this will display all the member profiles as select box - with "articlepost" you will be able to save member profile ID:
[cred_generic_field field='articlepost' type='select' class='' urlparam=''] { "required":0, "validate_format":0, "persist":1, "default":[0], "options":[ {"value":"0","label":"Select Member Profile"},[wpv-view name="member-profile-list"] ] } [/cred_generic_field]
You can see the dropwon now here at top of the page:
=> lien caché
Now I want information how you want to connect all this thins as Member profile is parent. Article is also parent and we are creating the Articles. Could you please give me sample example which writer should connect to which member profile. How you want to relate the post or how you want to save member profile ID with article post you are editing or creating.
OK, I'm a designer so sorry for all the pictures but it helps me explain stuff better.
Current User Scenario:
1 Members create article with cred tools. This case the user has created the "Test 333" article. The only way to associate a Member Profile with that Article is in the WP Admin opening the Test 333 article and going down to Post Relations and assigning it there. (see test 333 wp admin).
2. This then displays the Members Profile photo and names on that article. (see test 333 with members profile...)
3. This is done via "Add Writer view" (see test 333 for add writer view)
New User Scenario With "Minesh" Technology:
1. User creates or edits an article, they select their name from the Minesh Dropdown (see test 444 select member profile). click on "Submit" to save the changes
2. The Membership information shows on the article page (see test 444 member profile displays image)
Does that help or do you need any more clarification?
thanks,
Ronald E
Will this be do what we are trying to accomplish when released?
https://toolset.com/2018/03/toolset-beta-with-support-in-cred-and-layouts-for-relationship-forms/
I would like to know here - can article be assigned with multiple member profile?
OR
Lets assume - You are editing article "test-333" which has already been assigned with member. So If I select the member from CRED form (using Minesh dropdown of member profile) - the selected member profile should replace the already assigned member profile?
That is correct. Only one member profile can be assigned to an article.
Since the user only see their articles when they log in there won't be any use cases where multiple authors will be needed.
Well - shared FTP access details are not working at this end. Could you please send me working FTP access details.
I have set the next reply to private which means only you and I have access to it.
Ok - that code I've added using wp-admin to function.php file. Now FTP works fine.
I've added following code to your current theme's functions.php file:
add_action('cred_save_data','func_add_writer',10,2); function func_add_writer($post_id,$form_data) { global $current_user; if ($form_data['id']==3651) { // fetch existing writer posts and delete it $result = get_posts(array( 'fields' => 'ids', 'post_type' => 'writer', 'meta_query' => array( array( 'key' => '_wpcf_belongs_article_id', 'value' => $post_id, ) ))); if(count($result) > 0) { foreach($result as $k=>$v): wp_delete_post($v); endforeach; } // add new writer $data_arr = array( 'post_title'=> "writer for article ".$post_id, 'post_type' => 'writer', 'post_status' => 'publish', 'post_author' => get_current_user_id(), ); $insert_post_id = wp_insert_post($data_arr); update_post_meta($insert_post_id, '_wpcf_belongs_article_id',$post_id); update_post_meta($insert_post_id, '_wpcf_belongs_member_id',$_POST['_wpcf_belongs_member_id']); } }
Now, when you update the post - it will change the member information according to the selected member from the dropdown.
=> lien caché
Could you please check and confirm it works as your end as well.
Could you please confirm that it works for you as well.
WOW! Code poetry, very nice! Thank you. One more quick question. Will this dropdown member selector work when they create a new article? Or do they need to create the article first before they assign a writer via the dropdown?
Well - I've coded this chunk of code that will work for your CRED edit article form only.
I need to implement same kind of code that supports the add article needs. Could you please open a new ticket and share all required information, like link to add article form etc..etc and send me access details.
Even you can create a new ticket and assign it to me. 🙂