Skip Navigation

[Resolved] How to bind a user to a custom post type

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

Problem:
How can you connect users to posts?

Solution:
The simplest solution is to make the user the author of the post.

In circumstances where that is not possible, e.g. when you need to connect multiple users to a post, you can create a custom post type for the user (e.g. "profile"), make the user the author of that post, and then use post relationships to connect the profile post with the desired posts.

Relevant Documentation:
https://toolset.com/documentation/beyond-the-basics/post-relationship-concepts/

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

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Author
Posts
#610594

Hello,

On our website, we are listing the members of our organisation (mainly R&D companies).
We created a custom post type called "Member" which contains several custom fields.

We would like to offer the possibility for a logged-in user to front-end edit its Member profile, ie. a specific post from "Member" type.
For example, when the user logs in, we offer him a link to edit its profile (but not the wordpress user profile, the member profile, which is the company details).

So, I guess, we need to link specific users to a specific Member-posts. The thing is : how can we do that?

Note : we will create the users manually > Nofront-end/public user registration.

Thanks,
Brice

#610683

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Brice

The simplest way is to make the user the author of the post.

Note that for custom post types this option is disabled by default, you need to go to Toolset > Post Types and edit the custom post type in question and in the "Sections to display when editing..." section check the author field.

Then for a "My account" page you can create a View to show the post type and add a filter to only show posts where the post author is the currently logged in user.

Otherwise you could use a custom field to store the relationship, either a custom post field to store the user id, or a custom user field to store the post id.

#611013

Hi Nigel,

Thanks for your answer.
Solution #1 is indeed the simplest way and could do the job.

But the thing is : what if we need to create several users related to a member (it's gonna be the case for some members)?
Probably, solution #2 could handle the situation but I am not familiar with this trick.
> Could you please provide a link to documentation concerning this method?
> Can the next release of Toolset with many-to-many relationships help in some way to achieve this?

Thanks,
Brice

#611044

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-01-30 at 11.56.50.png

Hi Brice

There is nothing specific in the new post relationships that will help, though you can use post relationships.

What you would do it to create a post type for your users, and make the user the author of their "user post".

You can then "connect" multiple users to a post by making the "user posts" child posts of the member post type.

Otherwise, you can store the user ID of a user connected to a member post by making a "user id" custom post field on your member posts. Make it a repeatable field so that multiple users can be added to one member post.

You can then use that field in a Views Query filter to show posts where the linked user id field matches the current logged-in user.

Unlike the post-author filter, you can't compare the field to the current user directly, you must pass it via a shortcode attribute.

So, by way of example, if I have a custom field on the member posts called Linked User then I add a Query Filter to my View as shown in the screenshot, which uses the attribute "linkeduser". I could have called the attribute whatever I wanted.

Then, when I insert the View onto a page using the wpv-view shortcode, I add that attribute and generate the current user id with the wpv-user shortcode, like so:

[wpv-view name="member-of-linked-user" linkeduser="[wpv-user field='ID']"]

I think that is the most straightforward solution.

#612085

Hi Nigel,

Sorry for the delay. Thanks for your clear answer.
I will try method #2.