Skip Navigation

[Resolved] Sort View by author's current Role

This support ticket is created 2 years, 9 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Shane 2 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#2299547

Tell us what you are trying to do?
I am using a membership plugin to offer packages to subscribers. Packages assign a different role to the subscriber - for example: Elite, Premium, Standard. I want to sort posts that are submitted by the users - for example the sort order would be 1st Elite; 2nd Premium; 3rd Standard and so on. I prefer to have this set up so the sort by role is performed without the sort criteria being visible to the person that is querying the posts.

Is there any documentation that you are following?
I have reviewed several topics, but have not found one that fully addresses this problem. It seems as though if the current author role could be written to a custom field ("Author Role") for the posts that they have submitted, then the posts could be filtered by the Author Role custom field.

Are you aware of a solution with this or another method?

Some posts on this topic:
https://toolset.com/forums/topic/ordering-views-filter-output-by-author-role/.
https://toolset.com/forums/topic/sorting-view-by-author-role/

What is the link to your site? Staging site.

#2299945

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Chris,

Thank you for getting in touch.

Unfortunately you won't be able to sort the posts based on the user roles. Posts views can only be sorted attributes of the posts such as custom fields, post date, post title etc.

The author's role information are attributes of the user.

Thanks,
Shane

#2299967

Shane, thank you for the prompt reply.

The two links to topics that I provided seem to imply that there is a way to associate the author role to the post.

Is it possible to create a custom field in the post, and then have the author role dynamically linked to this custom field?

How can a user attribute be added to a custom field?

Thank you.

#2300023

In addition to the prior questions, would this concept work to add the current author role to the view? If so, can it be hidden?

https://toolset.com/documentation/user-guides/views/displaying-wordpress-user-fields/

#2300055

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Chris,


Is it possible to create a custom field in the post, and then have the author role dynamically linked to this custom field?

It is possible to do this with the use of some custom coding.

What can happen is that when your user is creating the post on the frontend you can then set this field's value based on the users role.

For instance if your create a select dropdown with the values Elite, Premium, Standard where elite has a value of 1, premium 2 and standard 3.

Then when an elite user creates a post the code will automatically set the custom field to one. However as mentioned this will require some custom code to achieve.

Thanks,
Shane

#2300063

Hi Shane,

I could see how this would work. However, once the post is submitted, the Author Role field is static - right? This would create a concern if the author role changes, for example if they downgrade or upgrade subscription.

Could the Author Role field be dynamic, so that it changes if the Author role changes. In one of the threads shared earlier, it seems like this was discussed, but it is a little above my skill level.

Thanks.

#2301243

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Chris,

If such is the case if the user role is downgraded then there will need to be a hook that should retrieve all their posts and then update the value to what they're profile was downgraded to.

Unfortunately custom coding is the only solution here.

You can get in touch with a Toolset contractor at the link below to discuss any further options on this one.
https://toolset.com/contractors/

Thanks,
Shane