Skip Navigation

[Resolved] Relationship between a WordPress user and a post-type not working

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
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 community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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)

This topic contains 4 replies, has 2 voices.

Last updated by tims-9 6 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#528231

I am trying to:
Make a relationship between a WordPress user and a post-type.

I have set the relationship in the CPT to User as parent, but i am unable to find a user when I type usercode. It stays on "No results found"

Any ideas?

#528377

Nigel
Supporter

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

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

Hi Tim

You can create Types post relationships between different post types, but nothing else.

You can't make post relationships out of users and posts.

I'm not sure what your use case is but you would normally connect posts and users using the built-in post_author field, or if that is not appropriate, then using a custom field on the posts where you store the associated user's id.

I can elaborate on that if needs be and you have some more details about what you are aiming to do.

#529596

Thanks,
Currently i have it as a custom text field. How can i make this access the user list within the admin area?

#529704

Nigel
Supporter

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

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

Hi Tim

If you want to store a User ID as a post custom field, and you want some way of selecting the user rather than manually entering the id in a text field, I would suggest you set up the custom field as a select dropdown.

There is no simple way to add the users to that dropdown that doesn't involve writing some custom code to populate the dropdown with the users and user ids.

There is an undocumented filter you can use for this: wpt_field_options.

I've written about it before here: https://toolset.com/forums/topic/post-field-select-field-containing-data-from-another-custom-post-type/#post-464519

In your case you will need to run a query that gets all the users and then uses the above filter to populate the select field options and values with the user names and user ids respectively.

If you need some more specific guidance let me know.

#530053

Thanks for your help.
This worked for me https://wordpress.org/support/topic/user-select-field/

The forum ‘Types Community Support’ is closed to new topics and replies.

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