Skip to content

Instantly share code, notes, and snippets.

@sscovil
Created May 14, 2014 02:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sscovil/535de15f134be519f6e4 to your computer and use it in GitHub Desktop.
Save sscovil/535de15f134be519f6e4 to your computer and use it in GitHub Desktop.
WordPress function to use with WP-Members plugin. Replaces the post index with a login page. To use, create a page and add the shortcode `[wp-members page="login"] ` to it, then get the ID of that page and put it on line 7 as the value of `page_id`.
<?php
//* Replace post index with login page for non-members
function premium_posts_05132014sms( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
if ( current_user_can( 'subscriber' ) || !is_user_logged_in() ) {
$query->set( 'page_id', '12' ); // Replace 12 with the ID of your login page
$query->set( 'post_type', 'page' );
}
}
}
add_action( 'pre_get_posts', 'premium_posts_05132014sms', 9999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment