Skip Navigation

[Resolved] Change post Author on CRED form but "search" for the right author?

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by Tulio 7 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#406825

Firstly, thanks for time! I appreciate it.

I'm trying to create a CRED new post form that allows me to change the author of the post. Based on everything I've found in your forums, I was able to successfully accomplish my goal by following the 2 links below.
https://toolset.com/forums/topic/cred-field-to-change-post-author/
https://toolset.com/forums/topic/generic-cred-select-field-wont-render-with-views-shortcode/

That form works but I need a second form that allows me to do almost the same thing but search for the user to select as the author of the post Something like the parametric search would be great but it's not exactly compatible with users in the same way as with post listings. With 1K + users/authors, the strategy of selecting the right user from a drop-down won't scale. Especially with two people that have the same name.

For background only:
In more detail, the site this will replace is registering 40-60 users/clients a day. I'm building a client portal that our sales team will be filling out and assigning the content to the clients so they can see how the progress is going with their account. Our sales team speaks to clients who call us on the phone and they go through an initial screening survey with them. I've made two CRED forms for the site, one to register the users/client and a second for our phone staff to fill out the client survey for the client and then to change the Author to the client's user. Finding the clients in the DB is done with a View that generates the client user list and is setup to order by descending user registered date. That helps because since they just made the user/client, the person's name should be within the first couple of names even if multiple specialist just created users. They should be able to find the right one without much trouble.

The dashboard that I made for the clients filters all the content by the currently logged in user. So clients only see their own stuff.

Now I need a way to post status updates to that dashboard. I created a CTP, "Client Updates," that are filled out by our staff using a CRED form. Although we could use the select field like we did with the client survey forms, I'm really nervous about what that will look like one month from now and one year from now. I've got a conservative estimate of 15K client accounts in one year. They're advertising on radio and TV so it could be even higher.

The only other option I've thought about is to create a "Client" CTP titled the user's First Name, Last Name, and userID (userID only to have a way to tell two identically named people apart in the post title) and to make the client surveys and client updates children of that CTP. That could work I think by using a View to pull up the right "Client" CTP comparing post Author to current logged in user. I asked in a separate support question about creating a CTP post at the same time as a CRED user form is submitted to elegantly create the correctly titled Client post. You can see that question here: https://toolset.com/forums/topic/create-a-new-ctp-post-when-a-user-is-created-with-user-registration-a-cred-form/

Maybe I'm going about this the wrong way and I would certainly appreciate your thoughts. Been a long time WP-Types client and I'm starting to use it more than before. It's really matured beautifully over the past few years and I'm both impressed and very pleased with it.

#406967

1. Using a View to populate a CRED generic Field is not suggested, for many technical reasons.
It's possible but not recommended.

Recommended would be creating your ShortCode that produces the necessary JSON for CRED generic Fields

2. It is not possible to use Parametric Search on User views, correct, and also, it is not possible to use them in Views that you altered programmatically with the code provided here (or can produce unexpected results):
https://toolset.com/forums/topic/cred-field-to-change-post-author/

3. What you need is a Select2 Select Field, something not provided in Toolset.
But it should be possible to add to your CRED forms:
hidden link

4. The approach with the additional CPT is right, but keep in mind, a Select Field, no matter if generic or not, populated with a JSON code coming from a View, will not allow Parametric Search in the Select Field itself.

==> Why do you not create a View, list all those CPT's that you plan to build (that allow parametric search for "users") and add a Link to the CRED form below each entry in that View?
This would enable you to navigate to the respective "user" related CRED Form (CPT) for each "user" found in the loop.

If your CRED form is creating a CHILD post of this "user" CPT, you can easily make it happen that the info will associate with the "user" in question.

Keep also in mind, K's of users or Posts queried by a View can produce Database Bottlenecks and slow down your Website.

Here is the DOC regarding how to create CRED forms for Child Post Content:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

#407276

Hello Beda,

I really appreciate the time you took to give me some vary valuable advice. I'll reply in order of the numbered list.
#1 & 2. Understood, I'll do my best to keep away from that route.
#3. I'm going to look into this, Select2 is pretty cool. Immediately my thoughts turned to how to create the dynamic list elements in the option value" ... /option format but still have it embed the right structure into the field when set. I think I just need to try it an un-confuse myself.
#4. Excellent, and understood.

#5 (Comments about your advice): That totally makes sense. I followed your advice and get everything to work as you suggested. Thanks for the link to create child content. That actually created a more natural workflow and solved most of the issues I created for myself 😉

Thanks!

But I do have some followup questions:
#1. What do you think is the best way to change the author of the user/client CTP from whoever on our sales team created the CTP to the user/client.

The only reason I think I need to change the author of the client CTP is because I need a way to filter the user/client CTP by author equal to currently logged in user on some kind of a dashboard page with a view that pulls up the right client CTP authored by the same user currently logged in. All the other relationships would then flow from the CTP and not the user. But I need that initial connection between logged in user and the right client CTP.

#2. That being said, all of the content tied to the client CTP worked perfectly. How do I create a "ShortCode that produces the necessary JSON for CRED generic Fields" to do it with a select field and follow your recommended way to do it and tie the client CTP to an actual client user account?

Thanks Beda, I really appreciate your time and advice.

PS. About the database bottleneck with many K's of users... totally agreed. I'm considering a recommendation to the client to put this site on AWS and use the Aurora DB to power this thing. Once the site launches they have a parent company that does the same thing and they want a clone of this site for them too... and they already have many k's of clients without this portal setup. I doubt the clients will hit the site too much but they got about 150 sales reps in total that will be hitting it all day to load the data. Both of the sites on one aurora instance should work. I can imagine WPEngine giving them the boot not too long from now.

Thanks!

#407366

1. What do you think is the best way to change the author of the user/client CTP from whoever on our sales team created the CTP to the user/client.

This is done purely in the Front End, correct?
So you can not let your Team choose the Author as in the WP Post Admin area is possible.

That means you need a Custom Code using our API for CRED and some functions of WordPress.
Basically, you will:
- Hook into the save process of the post that CRED performs
https://toolset.com/documentation/user-guides/cred-api/#csd
- Get the user/Client name from somewhere in the Post you are saving
(assuming you have the first and last name in a Field that you save for this post)
https://developer.wordpress.org/reference/functions/get_post_meta/
If you are using Types Fields keep in mind to use wpcf- prefix for the Field's Meta key
- Update the Post Title and name with this values.
https://codex.wordpress.org/Function_Reference/wp_update_post

Keep in mind filtering Posts by Author is possible ONLY as a Query Filter and not as a Parametric Search.
If you need it for latter, I rather suggest updating a Custom Field with this value which you can then use in your search

2. That being said, all of the content tied to the client CTP worked perfectly. How do I create a "ShortCode that produces the necessary JSON for CRED generic Fields" to do it with a select field and follow your recommended way to do it and tie the client CTP to an actual client user account?

That requires Custom Code.
You will use this WordPress API to construct a ShortCode:
https://codex.wordpress.org/Shortcode_API

You will return a $value, which is actually the label/value array in JSON format.
hidden link

Example below creates a Select Field population value set for GMT Time Zones:

function gmt_values( $atts ){
    $gmt_values = '
    {"value":"GMT-12","label":"GMT-12"},
    {"value":"GMT-11","label":"GMT-11"},
    {"value":"GMT-10","label":"GMT-10"},
    {"value":"GMT-9","label":"GMT-9"},
    {"value":"GMT-8","label":"GMT-8"},
    {"value":"GMT-7","label":"GMT-7"},
    {"value":"GMT-6","label":"GMT-6"},
    {"value":"GMT-5","label":"GMT-5"},
    {"value":"GMT-4","label":"GMT-4"},
    {"value":"GMT-3","label":"GMT-3"},
    {"value":"GMT-2","label":"GMT-2"},
    {"value":"GMT-1","label":"GMT-1"},
    {"value":"GMT+0","label":"GMT+0"},
    {"value":"GMT+1","label":"GMT+1"},
    {"value":"GMT+2","label":"GMT+2"},
    {"value":"GMT+3","label":"GMT+3"},
    {"value":"GMT+4","label":"GMT+4"},
    {"value":"GMT+5","label":"GMT+5"},
    {"value":"GMT+6","label":"GMT+6"},
    {"value":"GMT+7","label":"GMT+7"},
    {"value":"GMT+8","label":"GMT+8"},
    {"value":"GMT+9","label":"GMT+9"},
    {"value":"GMT+10","label":"GMT+10"},
    {"value":"GMT+11","label":"GMT+11"},
    {"value":"GMT+12","label":"GMT+12"},
    {"value":"GMT+13","label":"GMT+13"},
    {"value":"GMT+14","label":"GMT+14"}
    ';
return $gmt_values;
}

add_shortcode( 'gmt', 'gmt_values' );

This ShortCode is then used in the CRED Generic Field as values of the field.

You can dynamically construct your JSON but that requires more custom code.

If you need custom programming work which is beyond the scope of our support, I would suggest you consider contacting one of our certified partners from this link:
https://toolset.com/consultant/

You will get the custom assistance you need to get on with your project.

#412546

Forgot to reply to this - Thanks so much! You gave me the direction that I needed to go and I got it worked out based on your info.

Very happy, thanks again!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.