This Applies to
OTHER DOCS Available
Conditional shortcode to control access to portions of content (page, post, partial, etc.) based on the post type the user is currently viewing.
This is especially useful when using global excerpts as you can show a different “no access” message based on the post type – such as a different message for Pages, Posts, Products, LearnDash Lessons, etc.
To display a message if the current post type is a post…
To display a message if the current post type is not a post. So if it is a page, LearnDash lesson, etc. it would show…
[memb_is_post_type not=not types='post']Message[/memb_is_post_type]
You can also show an else message which appears if the criteria is not met. For example, we will show one message if the post type is a LearnDash lesson and another message if it is anything else.
[memb_is_post_type types='sfwd-lessons'] This message will show if the post type is a LearnDash Lesson [else_memb_is_post_type] This message will show if the post type is anything else (than a LearnDash lesson) [/memb_is_post_type]
You can also output the current post type using the shortcode with no attributes.
This shortcode is shown being used at 4:25 in the video below:
types: A comma-separated list of post types to test against. Example: types=‘post,page’
not: You can use the attribute “not=not”, to reverse the results.
You can this shortcode in default excerpts, partials, and custom shortcodes, and it will use the post type of the actual post the custom shortcode/partial is embedded in.
Example Use Case:
You could use this shortcode inside of the default excerpt setting under Memberium > Settings > Content Protection…
You don't have access to this [memb_is_post_type types='post']post[/memb_is_post_type][memb_is_post_type types='page']page[/memb_is_post_type][memb_is_post_type types='sfwd-lessons']lesson[/memb_is_post_type][memb_is_post_type types='sfwd-courses']course[/memb_is_post_type][memb_is_post_type not=not types='post,page,sfwd-lessons,sfwd-courses']content[/memb_is_post_type].
The output changes depending on the post type the user is viewing. As an example, if a user tried to access a LearnDash Lesson, but didn’t have access and the default excerpt appeared it would read as “You don’t have access to this lesson.”
If it was a page they didn’t have access to, it would read as “You don’t have access to the page.”
In the event it was anything except for a page, post, LearnDash lesson, or course, the message would be “You don’t have access to this content.”