Skip Navigation

[Résolu] Views Query Filter based on Access Post Group

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

Marqué : ,

This topic contains 23 réponses, has 4 voix.

Last updated by Team DNK Il y a 6 années et 11 mois.

Assisted by: Shane.

Auteur
Publications
#515084

Hello Support... I am trying to make a view that displays posts for my CPT "Projects" but only want posts to show up in the Query that the user has access to via Access Post Group settings. Just for clarification I am assigning the Access Post Group to individual Project posts and securing all projects via Access Post Types. This works great on the actual post page, but all posts in my View still show up irregardless of the Access Post Group assignment and settings.

I found the following Toolset documentation that seems to be what is needed just need a little guidance as to the proper way to accomplish this. Would value your assistance.

https://toolset.com/documentation/programmer-reference/views-filters/wpv_filter_query/

Kind Regards,
Dave

#515238

Noman
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Dave,

Thank you for contacting Toolset Support Team.

1. Can you please provide us step by step details that how you have created the View and added the query filter? (preferably with back-end screenshots)

2. Please send us back-end screenshot where you have set Access Post Group assignment.

Please make sure all Toolset plugins are updated to latest versions as a primary check.
Also can you please share your Debug Information with us so we can see it? I have enabled debug info box for your next reply:
https://toolset.com/faq/provide-debug-information-faster-support/

Looking forward to help you.
Thank you

#515345
Dont want in view.png

Hi Noman... I actually spent the last week helping the Toolset team track down two Access bugs but this is not a bug or at least I don't think so. Not Sure where the miscommunication is here but I really need assistance. If needed please forward this to someone in my timezone so another day does not go by.

ASSISTANCE NEEDED
Needing help filtering out a specific Access Post Group for users who do not have read access. I provided a screenshot and two Toolset Support threads as reference. The threads seem to deal with this very need as well. While this is something that should be configurable through the GUI in the future I need assistance as to how to properly go about adding the necessary code for a project management site I am currently working on.

REFERENCE 1
Here is links to similar requests.
https://toolset.com/forums/topic/how-to-limit-display-of-posts-to-users-within-the-current-access-group/

REFERENCE 2
Below is a link to a rather lengthy thread where Toolset support person "Christian" addresses a similar need as part of a much larger request. For your convenience I also provided an excerpt from the specific section of that thread which pertains to my request.
https://toolset.com/forums/topic/using-access-user-fields-to-filter-views-for-logged-in-users/

INQUIRY: These private "project posts" should only be visible to the staff who are members of that specific project group. Members of Project A should not be able to see documents or posts about Project B. Some staff may be members of both A and B. There may be lots of project groups, so with all the various possible combinations of membership, it would be silly to try to create separate Roles for these? A simple user group called Groups, with the tick box for each group will suffice, yes?

CHRISTIAN: Toolset Access limitations can be based on user role, or on the individual user - but not on a user group. This means that you would need separate user roles for each combination of project groups to be able to fully manage this from the WordPress admin area and take full advantage of Access's restrictions interface. If you are able to write custom PHP, it's possible to use the wpv_filter_query function to modify your WordPress queries and restrict the responses to those post groups to which a user has access. More information about that function can be found here:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

#515429

Noman
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Dave,

Thank you for providing more details. I understand from the screenshot what you want to achieve.

Post Group Access works for only Single post but not for the archive page which displays “List of all Posts”.

Currently the only method to achieve this is using this code snippet. Please add this code in your theme’s functions.php file:
https://toolset.com/forums/topic/how-to-limit-display-of-posts-to-users-within-the-current-access-group/#post-467760

- Please replace: {YOUR-GROUP-NAME} with your post group name on line# 10.
- Adjust $role and $roleA values.

Thank you

#515438

OK... We seem to be going in circles here. You have sent me back to the very link I provided. Tried it again and having trouble getting it to work. Really need some guidance as I am sure I must be missing something obvious here.

My Access Post Group is "TeamSDA" and this code seems to have the check for user role hard coded for a single user role. I would like it to look at the logged in users role. I see this in the link I provided as well but not sure how to integrate that into the code as I can't seem to get the original code working properly.

The below code was my attempt to get this working with the hard coded user WordPress default role "subscriber" and my Access Post group "TeamSDA". Note Subscriber Role does not have read access for the TeamSDA Access Post Group.

One further note, the post type is the built in WordPress Page type and this is a page content layout displaying the view, it is not an archive layout.

I hope this gets us on track and I appreciate your help Noman.

function func_chec_post_group($query) {
 
  if ( is_post_type_archive( 'project' ) ) {
 
         /// HERE check your $role 
         if ( $role == $subscriber) {
              $meta_query = array(
                                 array(
                                                'key' => '_wpcf_access_group',
                                                'value' => 'wpcf-custom-group-TeamSDA', 
                                   ));
}
}
$query->set('meta_query', $meta_query);
}
add_action('pre_get_posts', 'func_chec_post_group');
#515692

Noman
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Carlos,

To debug this issue I will need to take a look at your setup. So I need to request temporary access (WP-Admin and FTP Login info) to your staging site

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the Links to the [View] Edit Screen and the [Page] Edit Screen where you have added this view.

Looking forward to help you.
Thank you

#515831

:::::::::::::::::::::::::::::::::::::::::::::: IMPORTANT ::::::::::::::::::::::::::::::::::::::::::::::

Noman... I believe there is something wrong with this thread. Firstly it was changed to a debug style thread and secondly you keep referring to me as Carlos.

I have worked with you before and you have always been attentive. This is getting quite frustrating as my request is rather simple and this is not a bug, that is unless you are telling me that views does in fact limit what is displayed base on the Access Group setting for a loges in user.

Please confirm this thread is functioning as you keep referring to this as a bug, sending me info I have actually already provided and referring to me as Carlos. I am loosing valuable time and really need your assistance understanding how to implement this functionality with toolset. Further if this was a bug, I would not be able to grant access to the server for legal reasons as this beta site shares space with another live site.

POSTS BY DAVE
April 19, 2017 at 7:37 pm
April 20, 2017 at 1:54 pm
April 20, 2017 at 5:14 pm

#515882

Noman
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Dave,

First of all I am extremely sorry for the wrong name, somehow the message opener gets copied wrongly through my Word doc, however the replies I have sent are to help resolving your particular issue.

- Basically it's not a bug, but something that Toolset does not offer and I know I have sent you the same code only because that's the only solution to the problem I could find after testing various things, there could be another approach that is by creating our own shortcode and then use our custom shortcode in the View's Condition to exclude particular restricted posts. Toolset Access only restricts content that is on a Single post (post content template) and it is not supposed to restrict content from a list or View loop as we like to have it and we don't have this feature yet as long as I can see.

- In this thread I cannot see debug information and neither I have WP-admin and FTP info attached to this thread, so I requested that. If it's an old site whose login access I already have please let me know and I can go into your old tickets to find that, but please if you add here it will be easier for us to manage.

- Now to use the above given code from another thread we need to try implement it in your site so that we get it working exactly with your setup and that's why we need login. Else I can try, modify and send you updated code but there could be difference as I do not have same post groups, post types, conditions, etc... as you have in your site.

Again I apologize for some confusions that we had. Thank you

#515884

Hi Noman... Thank you, my main concern was that something was not working properly with the forum thread as we seemed to be not getting through to each other.

Now onto my Views & Access Post Group functionality need. What specific configuration info do you need as it seems I may just simply have something misconfigured in the code or named wrong? I ask as I can't allow access to the site at this time as it is on a server with other active sites.

#515918

Noman
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Dave,

A this point I am not sure if it can only be some configuration or Access settings or something else. If you can at least provide temporary WP-admin access that will be sufficient, if possible?

- Please also add the page and other links that are involved in this issue.

Alternatively, you can send us Duplicator package files of your site using the Duplicator plugin for testing purpose (excluding content / uploads folder), and we will try to check this issue further locally: https://toolset.com/faq/provide-supporters-copy-site/

Your next answer will be private, if none of the above options will work for you we will do some similar setup at our end anyways to help resolve this issue, so please advise.

Thank you

#515936

Let me try again as what you are asking still requires stripping out a lot of sensitive info. And please have look at the code provided earlier if you haven't already.

--- Using a View with a custom search updating via AJAX on a default Page post type inside of the pages Content Layout Editor.

--- The Content Layout has a View Cell that is querying a CPT by the name of Projects. Two of the project posts have an Access Group assigned to them by the name of TeamSDA.

--- When using the above code all posts are visible no matter whether I am logged in as Admin, Author or the Subscriber user role types.

--- If the above code is the only current method for controlling what a view outputs based on Access Post Groups it seems like I must simply have something misconfigured, named wrong, using a hyphen instead of an underscore, needs the curly braces, the Post Group name needs to be lower case or some such thing.

The desired functionality is pretty straight forward and really seems like it should be configurable via the GUI, but as stated, it is currently only available via a properly configure snippet of code that needs to be placed in the functions.php file. Would really value if you could just take a look at the code I have provided and advise as to what you see.

Kind Regards,
Dave

#515948

Additional info to above... Tried to play with this code some more on my own and not getting anywhere, in fact it breaks the AJAX search and sorting I have set up. As a test I installed another membership software I own called MemberPress just to see how that worked within the beta site and the View specifically. It took all of about 20 min to install setup and test and it fully locks down the appropriate content as well as removes it from the View query.

I really want to be using Toolset as a single source solution. I am happy to go the custom code route for now which is not going smooth for me but more importantly the Toolset Suite needs to handle this sort of thing out of the box. When securing content, the content should be removed completely unless the user has the proper credentials.

I hope this additional info is helpful for future development and I look forward to your response with more complete guidance with how to hand code for the time being.

#517001

Shane
Supporter

Languages: Anglais (English )

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

Hi Dave,

As Noman is currently on holidays I will be handling this ticket.

Taking a look at this it seems that this issue is similar to the issue that Beda mentioned here : https://toolset.com/forums/topic/important-need-senior-level-assistance/#post-516181

However what I would like for you to do is to provide me with admin access to the website so that I can have a more detailed look at this.

The private fields will be enabled for your next response.

Thanks,
Shane

#517013

Hello Shane... As you are picking up on this thread from another support person please read through it in it's entirety as well as the link you provided as it is actually my thread trying to get support for this thread.

I am trying to be patient, I know these things can get a little sidetracked, but over the past three weeks I have lost significant time to two Access bugs and my request for guidance in this thread as well as the other thread.
https://toolset.com/forums/topic/important-need-senior-level-assistance/#post-516181

Please bring these two support threads to the attention of a senior level supporter and I look forward to resolving how to go about implementing this functionality via the Toolset workflow.

#517241

OK, this is me again.

I am 2nd Tier Supporter, which is what you ask for in both threads.

Please let's stop tracking the same issue on 2 Tickets.

This will lead nowhere.

@shane, please close this ticket here if @dave agrees.

I handle the issue here:
https://toolset.com/forums/topic/important-need-senior-level-assistance/

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