Description
Filters the membership products required to access content (by post ID).
Parameters
$post_products
(array)(required) The membership products assigned to the post.
$post_id
(integer)(optional) The post ID being filtered.
Usage
The following example shows how to use this filter hook to apply all posts in a category to a specific memberhship:
/** * You can have all posts in a category set to require a membership * by using the wpmem_post_products filter hook and WP's has_category(). * * @see https://rocketgeek.com/plugins/wp-members/docs/filter-hooks/wpmem_post_products/ * @see https://developer.wordpress.org/reference/functions/has_category/ * * NOTE: This filter requires that you also have the category blocked (or at least * all posts in the category marked as blocked). The simplest way to do that is to * use a filter to make sure any post in the category is viewed as blocked. * @see https://rocketgeek.com/code-snippets/use-a-filter-to-block-a-category/ */ add_filter( 'wpmem_post_products', function( $post_products, $post_id ) { // What is the category: $category = 'my-blocked-category-slug'; // What is the required membership: $membership = 'my-membership'; $has_category = has_category( $category, $post_id ); if ( $has_category ) { return array( $membership ); } return $post_products; }, 10, 2 );
Changelog
- Introduced in 3.3.5
Source
wpmem_post_products is located in inc/class-wp-members-products.php