Access rules you set up for post types do not apply to posts displayed using a View. Instead, you need to use conditional HTML output or Access shortcodes in the Views Loop Editor directly.
To display posts in a View according to the Access rules you set up for a Post Group, there are three main steps you need to do:
- Enable hidden custom field that contains Post Group ID
- Get the Post Group ID
- Use the conditional output inside a View Loop
Enable hidden custom field that contains Post Group ID
Post Group ID enables unique identification of each Post Group. This field is hidden by default. In order to use it you need to enable it.
Get the Post Group ID
After enabling the _wpcf_access_group field you need to get the exact ID for the Post Group you want to target. For this, you need to use a shortcode to display the Post Group ID on the front-end. After that, you can remove that shortcode.
Use the conditional output inside a View Loop
As the last step you need to go to your View and edit it. Select the part of the Loop that you want to be shown or hidden based on Post Group ID and add a condition to it.
What you need to do | How it looks like |
Edit a View that displays your posts.
Click the conditional output button to add HTML conditional to your View Loop. |
|
Add a condition to check the value of hidden custom field _wpcf_access_group against Post Group ID from previous step.
This allows you to show or not show the content depending on the Post Group assigned to the current Post in the loop. |
The conditional markup added to your View will look something like the following:
[wpv-conditional if="( $(_wpcf_access_group) eq 'wpcf-custom-group-70a37754eb5a2e7db8cd887aaf11cda7' )"] [wpv-post-title] [/wpv-conditional]
The example above will display the post title only if the current post in a loop belongs to a Post Group you set in the Insert conditional shortcode dialog.