• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Store
    • Cart
    • Checkout
  • Blog
    • Basics [Free]
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Contact
  • Sign In
  • Show Search
Hide Search
Home » Tips and Tricks » How to hide posts completely

How to hide posts completely

Chad Butler · Feb 10, 2015 ·

There are times when a site operator may wish to completely hide certain posts – either all posts that are blocked, posts of a certain category, or other possibilities.  While the main process that the plugin operates on is to show titles and excerpts on summary pages to drive users to conversion (registration), that is not a one-size-fits-all solution.

WP-Members 3.0 will begin to introduce certain administrative options to manage this process. But until then, here is a discussion of how to unload posts from display depending on criteria that you establish.  

This article is only available to WP-Members Support Subscribers. If you have an existing subscription, please login below. If you do not have a current support subscription, you can purchase a support subscription here.

Already a Member? Log In Here
   
Forgot password? Click here to reset

To gain full access to WP-Members premium content, a current support subscription is required. You can purchase an annual support subscription for as little as $59, which provides you with access to priority support, a customer support forum, access to code snippets, and more.

Why wait? Choose your subscription option here.

[
Why join?]

Tips and Tricks actions, is_user_logged_in, tips, wp-actions

Welcome to RocketGeek Interactive › Forums › How to hide posts completely

Tagged: actions, is_user_logged_in, tips, wp-actions

  • This topic has 4 replies, 2 voices, and was last updated 6 years ago by Chad Butler.
Viewing 3 reply threads
  • Author
    Posts
    • February 10, 2015 at 12:53 pm #7168
      Chad Butler
      Keymaster

      There are times when a site operator may wish to completely hide certain posts – either all posts that are blocked, posts of a certain category, or ot
      [See the full post at: How to hide posts completely]

    • February 10, 2015 at 1:19 pm #7170
      jkirker
      Participant

      ROCK ON!

    • February 12, 2015 at 3:49 pm #7182
      jkirker
      Participant

      Chad, this has created a new issue. When posts from categories are hidden because the user is logged they get a 404 instead of a login prompt.

      How would we go about prompting people to log in for things like this?

      Curious to get your thoughts.

    • February 14, 2015 at 6:28 am #7187
      Chad Butler
      Keymaster

      I’m sure we can figure out a solution, but I’m not sure off the top of my head what the solution will be. I’ll need to test a couple of things. Unfortunately, I am traveling and am not in a place were I can test things out. I’ll be back on Sunday evening and will see if I can come up with something then or Monday.

      • February 16, 2015 at 2:09 pm #7205
        Chad Butler
        Keymaster

        I thought about a couple of different approaches to this, most of which did not really work all together smoothly.

        I think the best solution is to redirect the user to a login page if the category being requested is a blocked category. Here’s a code snippet that does that:

        add_action( 'template_redirect', 'my_blocked_cat_redirect' );
        function my_blocked_cat_redirect() {
        	// get the category ID
        	$cat_id = get_query_var( 'cat' );
        	
        	// if the category ID is the blocked category, redirect to login page
        	if( $cat_id == 4 ) {
        		wp_redirect( '/login/?redirect_to=' . get_category_link( $cat_id ) );
        		exit();
        	}
        }

        The first thing to note is that in order to redirect, we need to do that before headers are sent. template_redirect is one of the later actions where we have the post info or category ID and can still do this.

        You will need to change the category ID that the if logic is testing for to match the ID of your blocked category.

        Next, you will need to create your own correct redirect URL. The example uses the slug /login/ so if your login page is different, that will need to change.

        The redirect link also sets up a ?redirect_to= parameter for the link so that the login page will redirect back to the originally requested category page. I used get_category_link() to build that value. This uses the category ID for the requested category.

  • Author
    Posts
Viewing 3 reply threads
  • You must be logged in to reply to this topic.
Log In

Ready to get started?

Join Today!

© 2021 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Refund Policy