Skip Navigation

[Résolu] Filter CPT by User Roll

This support ticket is created Il y a 2 années et 8 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 réponse, has 2 voix.

Last updated by Christian Cox Il y a 2 années et 8 mois.

Assisted by: Christian Cox.

Auteur
Publications
#2135741

I have a CPT Editors(membership) Profile. It is connected to the WordPress User.
I now need to create a view showing only one specific user rolls in the view. The view consists of various fields from the CPT but it must just show one specific user role' (Ie: Peg editors - pre approval) profiles.

The application where I want to use this is where members of a site register as members of the site. They then complete a basic membership Profile. Once This information is captured the site admin is then notified where they will then approve the Profile. Once the Basic profile has been approved the member will then log back in and complete the Profile whereafter it will be shown on the website.

The flow is as follow:
User registers with toolset users form. The roll "Peg editors - pre-approval" will be assigned to the user. Once this has been done, The user will then open an Editors profile form (post form). They will complete the member's basic Profile and the process will save.

At this stage the admin must then access the "Peg editors - pre approval" rated profile and approve the profile. Once it has been approved the User Roll must be changed to PG Editors.

Right now everything is functioning 100%. Except I am trying to create a view were the profiles for only the "Peg editors - pre approval" . No other Profiles must show. This is where I am lost. I am getting the view to work but I can not limit it only to the " Peg editors - pre-approval" user.

The view will be done in a grid where each of the Profiles still to be approved will be shown.

The view grid will have the post title of the members still to be approved and by clicking the heading it must open up the member's profile. At this stage I want to have a functionality that there will be a button with the option to approve the profile. At this stage the User role must be updated to "Peg Editors".

I need some advice on how to achieve this aswell

#2136889
Screen Shot 2021-08-08 at 10.50.40 AM.png

I have a CPT Editors(membership) Profile. It is connected to the WordPress User.
Hello, I assume you mean that each WordPress User is the post author of his corresponding Editors Profile post. If not, please explain how the User is connected to the post.

Except I am trying to create a view were the profiles for only the "Peg editors - pre approval" . No other Profiles must show.
One way you can achieve this is with two Views in a nested structure. Create one View of the Editor Profile post type and add a post author Query Filter, where you select the option "Post author is set by the parent User View". See the screenshot here for an example. If you have already created and Editor Profile View, you can add the post author Query Filter to the existing View.

Next you need a View of Users. This is only possible in the legacy View editor, since User View creation is not supported in the Block Editor. You can enable the legacy View editor in Toolset > Settings > General in the "Editing Experience" section. Enable both the block editor and the legacy editor. Create a new View of Users and configure the View to only show Users from the pre-approval role. In the Loop Editor, click "Skip wizard". Place your cursor anywhere between the wpv-loop tags and click the Fields and Views button to insert your View of Editor Profiles. This will create a nested View structure showing Editor Profile posts where the post author must have the pre-approval role.

One potential problem with this approach is that it is not easy to sort the displayed results, since the outer loop of Users dictates the main sort order. If you need to sort the list of Editor Profile posts more logically, you may need a custom code solution. For example, instead of using a nested View, you could create a custom shortcode that returns a comma-separated list of all the User IDs of Users in the pre-approval role. You might use the WP_User_Query feature of WordPress for this:
https://developer.wordpress.org/reference/classes/wp_user_query/
If your shortcode returns a list of the correct User IDs like this...

1,2,3,4,5

..then you can use this custom shortcode to set the post_author Query Filter of your View of Editor Profiles. You would adjust the post_author filter settings to respond an ID in a shortcode attribute like "author", then place your custom shortcode in the View shortcode attribute "author". For example:

[wpv-view name="your-editor-profile-view" author="[your-custom-shortcode][/your-custom-shortcode]"]

To use a custom shortcode in another shortcode attribute like this, you must register the shortcode name in Toolset > Settings > Front-end Content > Third party shortcode arguments.

The view grid will have the post title of the members still to be approved and by clicking the heading it must open up the member's profile. At this stage I want to have a functionality that there will be a button with the option to approve the profile. At this stage the User role must be updated to "Peg Editors".
You can use Toolset Forms to edit a User's role. Each Form has a configuration option that sets the User role upon Form submission, so you would select the post-approval role for this Form. You would remove all the input fields from this Form and keep only the Submit button and the Form Messages field. Change the Submit button text to something like "Approve". If you place the Edit User Form in the loop of your View of pre-approval Users, the Approve button will be displayed for each User in the View results.

If you have more questions about editing User roles with Forms, let's create a separate ticket so we can discuss in more detail.

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