[Résolu] Method for user to choose post as « favorite »
Ce fil est résolu. Voici une description du problème et la solution proposée.
Problem: I would like to allow my Users to "favorite" posts.
- Add a number custom field to the User's profile. This number will store the favorite post ID.
- Create a Form that edits the current User's profile
- Remove the number field from the Form and replace it with a generic select field that stores the value of the favorite post ID:
- Replace 12345, 67890 with the View's ID, or a comma-separated list of View IDs if you want to apply this filter to more than one View.
- Add the following custom code that will capture the selected post ID and save it in the User's favorite post field:
I'm creating a membership website for a client. Membership is free, just requires registration. Upon registration, the new user is given a custom role and access to hidden content controlled by Access. Members are also allowed to choose from a list of service providers "agents" which is simply a custom post type with custom fields containing agent info.
I need to:
1. Allow members to choose an agent from a dropdown list (this could be handled on the member's profile CRED page).
2. Restrict the member to choosing only 1 agent (important).
3. Display the agent's name on the member's account page (this would just be the title of the cpt). This is in case the member forgets which agent they're working with...
4. Make sure an agent (just a post, remember) can be chosen by unlimited members.
This sorta sounds like designating a post as a "favorite," except that members can only have 1 favorite agent post.
What's the best way to go about this?
I forgot to mention that I already have the basics of the membership site created, as well as the agents custom post type...just need help with the agent-post/member association.
Hi, it sounds like this could be accomplished with a User custom field that stores the ID of an Agent. Can you tell me more about Members and Agents?
- Are there custom post types and custom posts that represent Members and Agents, or are they simply custom roles assigned to the standard User in WordPress?
- If they are post types, do you have any post relationship set up between the post types?
- If they are custom roles only, do you want your Members to log in to the wp-admin to modify their favorite, or do you want to set up a form on the front-end of the site where they can manage this?
"Member" is a custom role assigned to a user when they register from a specific Gravity Form. Members will be accessing hidden content and doing other things on the site, including managing their own profile via CRED forms.
"Agent" is a custom post type with a custom field group. The agent posts are essentially bios and contact info. Pretty basic. Agents won't be users on the site.
I want to prevent Members from seeing/accessing wp-admin. (I know there are posts about this, and I'll handle that separately). I want Members to manage their account via CRED forms, and as part of that, be able to select 1 Agent as their desired agent. So...an Agent post/bio can be the choice of many Members, but a Member can only choose one Agent.
Does that clarify things a bit?
I can give you login credentials to the dev site if you like.
I'm not following you... Are you suggesting that Members create the Agent posts? Members are not allowed to create posts of any kind in this system. All Agent posts (which are essentially bios) are created by me or by my client in the WP backend. Members will only be allowed to favorite an agent post that has already been created, presuming we can solve this...
Ok since this is a limitation as they are not able to create posts.
However if we use the favourite post plugin then the user can favourite multiple Agents.
I wouldn't be able to assist with a custom solution for the user to favourite a post as custom coding is out of our forum scope.
The best non-custom coding method is to use a child post or what you can do is when the user is creating their profile you can provide them with a list of the agents that they can select from on the form.
Choosing an agent when the member creates their profile is what I'd like to do. Hopefully they can also change the agent if they edit their profile with a CRED edit form. Can you point me to the documentation for how'd I'd use child posts for this, and how I'd connect the select menu to the Member CRED form?
OK, this looks like a fair amount of fuss for what seems to be a simple concept.
Also, you wrote, "What you can do is to Create a custom field on your Members Role using our Types plugin," but didn't provide further explanation as to what kind of field or how it works. I'd like to learn and understand the relationships here rather than just cut and paste code, so explanations are helpful, and may be useful to someone else down the road too.
Christian Cox wrote, "it sounds like this could be accomplished with a User custom field that stores the ID of an Agent."
If so, how can I accomplish this?
Maybe Christian Cox can jump back in here since that's what he proposed initially... Would it be better to create an Agent role with custom user fields for their bio info instead of using an Agent custom post type? The only reason I used a custom post type for Agent (instead of a custom role) is because I thought it'd be simpler, especially since Agents don't need user accounts on this system.
To recap, a Member (custom role) needs to be able to select 1 Agent (an Agent can be either a cpt or custom role, whichever is easier. I don't care which at this point). An Agent can be the "favorite" of many Members, but a Member can only have 1 Agent.