Skip Navigation

[Resolved] Profile Editing with custom post

This thread is resolved. Here is a description of the problem and solution.

Problem:

The post form contains all the data from the custom post type, however it doesn't "correspond" to a user and therefore can't be edited/doesn't work.

Solution:

I suggest you try these:

https://toolset.com/forums/topic/profile-editing-with-custom-post/#post-1790055

Relevant Documentation:

https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/

This support ticket is created 3 years, 7 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by NathanG920 3 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1789819

Tell us what you are trying to do?

I'm trying to create an "Edit Profile" section for users on my site, however my user data works a little differently. Similarly to how it is described in this thread:

https://toolset.com/forums/topic/custom-search-for-users-view/

the users are bonded to a custom post type called 'members' where the information they enter during the sign up process fills out the custom fields of their linked 'member' custom post. This way, all the user data can be searched using a view and displays their contact information etc.
The majority of the user data however is empty, whereas all of the main data is in their corresponding 'member' post, which also links to the user in a custom field "associated user".

I'd like to be able to make it so in the "edit my profile" section, the user can edit their details from their corresponding 'member' post, rather than editing their user data (as there isn't any to edit anyways). However, in following the guide for creating a profile editing section, i can only create a user form or a post form. The user form doesn't contain the data that i need to link it to, however it works correctly in that it displays the data linked to the logged-in user. The post form contains all the data from the custom post type, however it doesn't "correspond" to a user and therefore can't be edited/doesn't work. Is there a way around this so that i can make something like this work?

Is there any documentation that you are following?

https://toolset.com/forums/topic/custom-search-for-users-view/
https://toolset.com/course-lesson/using-forms-to-create-an-edit-your-profile-page/
https://toolset.com/course-lesson/creating-a-my-account-page/

Is there a similar example that we can see?

The old website (before i started re-styling) does do this, and works correctly, however i had to remove the theme in order to overhaul the design, and all the old code is built-in to the old theme. It also doesn't use Toolset, however if needed I can show the section or the relevant code if it helps, just let me know.

What is the link to your site?

Currently locally hosted.

#1790055

Hello,

For the problem:

The post form contains all the data from the custom post type, however it doesn't "correspond" to a user and therefore can't be edited/doesn't work

I suggest you try these:
1) Make sure each "members" post's author is different WordPress user, one user can have only one "members" post
https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/
2) Create a post form for editing "members" post
3) Create a page with view block:
- Query "members" posts
- Filter by post author is same as current logged-in user:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/
- In view's loop display the edit post form link of step 2)
More help:
https://toolset.com/course-lesson/front-end-forms-for-editing-content/

#1791113

Hi Luo,

Thanks for getting back so quickly. It took a little time to test what you suggested, but i think I've managed to get most of it working now so thank you!

I'm a little unsure though, i managed to change all the post authors to the relevant user/member, so now the forms do link correctly to the currently logged in user, however i had to skip a part of your first step where "one user can only have one member post" because the link you provided " https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/ " automatically redirects to a different post that doesn't really correspond. I tried exploring the relationships section of Toolset a bit, but i couldn't find out a way to link the member post to a user (the only other options were other kinds of posts, so I'm a bit confused). It does obviously still work currently, but I'd prefer to do it the right way the first time like you suggested so that no unknown error pops up in the future.

The one other problem - in the form itself, there's a possibility to edit taxonomies, however one of my taxonomies has a LOT of entries, and so it ends up being an insanely long list on the page. Is there some method of styling the form itself so that rather than the 100+ entries appearing all together, there's some sort of enclosing box with its own scroll-down to limit the amount that appear all at once? (Something similar to how it appears on the WordPress back-end when you have a lot of options for a certain taxonomy).

Thanks again for all the help,
Nathan

#1792389

Q1) but i couldn't find out a way to link the member post to a user
The Toolset relationships are based on post types, in order to link the WordPress user with posts, you will need to setup the member post author as the specific WordPress user, then use the member post to connect other custom post type posts.

Q2) The taxonomy fields of Toolset post forms work just like the WordPress backend taxonomy input boxes, for example, you can setup a flat custom taxonomy(like the Tags)
https://toolset.com/course-lesson/creating-a-custom-taxonomy/
then in front-end Toolset post forms taxonomy fields, you can input two or three letters, and get the related terms.

#1792691

Hi Luo,

Q1) I'm not too sure i follow what you mean. I've already set up the author of the membership custom post type as specific users, so they are linked properly already. It works as intended (so the logged in user only sees their own linked membership post), but i'm not sure what you mean about "using the member post to connect to other custom post type posts". I don't need the membership post to link to anything else besides the user, i just wanted to make sure it was correct as-is because you mentioned something about making sure "each user only has one associated member post", which isnt the case currently, although the Author of the post being a specific user is correctly set-up.

Q2) I'm not too sure i follow this either, the form is set up and does display all the right information, the taxonomy is included and does work, however on the front end, the taxonomy is a "checkbox" type, and so it displays ALL the taxonomies at once which takes up a ton of space. I know i can switch the display to a dropdown menu, but the checkbox is preferrable, so i was just wondering if its possible to "style" the form so that when it displays that list of checkbox items, rather than it being a super long list that takes up tons of space, it turns into a smaller box that you can scroll through that only displays, say 5 items at a time. Is something like that possible?

Again, thanks for all the help. If theres any extra information you need or if i haven't described something properly please let me know.

#1792775

Q1) Yes, you are correct.

And maybe in the feature, you can setup a post view: search the WP users by the custom fields of member posts, or setup relationships with WP users with other post types.

Please have a look at the document I mentioned above:
https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/

Q2) No, there isn't such kind of built-in feature within Toolset Views plugin, you will consider custom codes, for example, use a scrollable DIV tag to display those checkboxes, see demo here:
https://stackoverflow.com/questions/9707397/making-a-div-vertically-scrollable-using-css
More help:
hidden link

#1794063

My issue is resolved now. Thanks again, I really appreciate all the help.

#1794209

Actually, sorry to switch after resolving, but after testing out what you mentioned a bit I was wondering:
Is it possible, in the View Query Filter, rather than using a filter to make it so that the Post Author is the same as the logged in user, is it possible to do that with a custom post type instead?
So instead of "Author = Logged in User", is it possible to use a filter like: "Associated user = Logged in user"?
It may be a little different, but it solves having to re-edit all the members to switch their individual post authors to individual users, as there's already a CPT that associates a user to a post, so i was wondering if it's possible to use that instead?

#1794921

No, as I mentioned above, you can setup direct relationship between the post with WP user by setup this user as post author, there isn't "Associated user" relationship.

#1795269

Sorry, I don't think i explained it properly. As far as my understanding, the way the view query would work in this situation is that it checks the current logged in user ID, and then finds any 'membership' posts that have an author with the same ID, and then only displays those.

I have a custom field that i've already created - called "Associated user", which is a select-dropdown of a list of all the users. So what i meant was, rather than using a query to check if the logged in user ID matches with any post author ID's, if its possible to create a query that checks if the logged in user ID is the same as any of my "associated user" custom field ID's. Obviously it's a little different as theres already a query option for Post Authors, but i was wondering if it's possible to create a similar effect with a query using a custom field instead?

#1795303

Yes, it is possible, for example, you can try these:
1) Create a post view
- Query your custom posts
- Filter by:,
Select items with field:
Associated user is a string equal to VIEW_PARAM(uid)
https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/#source-for-compare-value
Shortcode attribute The value for the filter comes from an attribute in the View shortcode

2) Create a page, you can display current login user's ID with shortcode:
[wpv-current-user info="id"]
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-current-user
And pass it as view's shortcode attribute of step 1), like this:
[wpv-view name='MY-VIEW-SLUG' uid='[wpv-current-user info="id"]']
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-view

It should be able to do what you want: create a similar effect with a query using a custom field

But there are lots of limitation using above method, for example:
1) You need to setup the "Associated user" field option value manually
2) If this user is deleted, the custom field "Associated user" value won't be updated automatically.
...

#1796845

My issue is resolved now. Thank you!

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