• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Restrict access to custom post type on the front end.

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Restrict access to custom post type on the front end.

This topic is: not resolved
  • This topic has 3 replies, 2 voices, and was last updated 11 years, 7 months ago by Brad Dalton.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • October 3, 2014 at 3:27 am #126644
    jourdain
    Member

    Hi guys,

    I have a little question that hopefully I can get some assistance with.

    I have added a custom post type to my site using the following tutorial by Brad Dalton http://wpsites.net/web-design/add-custom-post-type/.

    So my code looks exactly like his tutorial apart from the fact I have changed the name of the custom post type and also allowed categories in the taxonomies.

    //* Create Custom Post Type
    add_action( 'init', 'add_custom_post_type' );
    function add_custom_post_type() {
     
    	register_post_type( 'members',
    		array(
    			'labels' => array(
    				'name'          => __( 'Members', 'wpsites' ),
    				'singular_name' => __( 'Member', 'wpsites' ),
    			),
    			'has_archive'  => true,
    			'hierarchical' => true,
                            'menu_icon'    => 'dashicons-admin-users',
    			'public'       => true,
    			'rewrite'      => array( 'slug' => 'members', 'with_front' => false ),
    			'supports'     => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes' ),
    			'taxonomies'   => array( 'category' ),
                            'menu_position' => 2,
     
    		));
    	
    }

    Now what I would like to do is restrict access to this post type on the front end. I know this can be achieved with a content restriction plugin but I was wondering if there was a way to achieve this within the code. So I only want this post type to be seen by a "Group Leader" or "Admin" role.

    If this cant be achieved in the code then please suggest the best plugin / solution to achieve what I am looking for.

    I look forward to hearing your replies.

    Jourdain

    October 3, 2014 at 3:51 am #126647
    Brad Dalton
    Participant

    Depends on what you want to restrict http://wpsites.net/wordpress-admin/restrict-access-to-custom-post-types-by-users-capability/


    Tutorials for StudioPress Themes.

    October 3, 2014 at 6:23 am #126659
    jourdain
    Member

    On second thoughts, I am going to be using genesis featured widget amplified to display the posts from the custom post type in a widget. Would it be easier to display the widget conditionally?

    Basically I am creating a teacher support page but the content needs to be visible only when the user role is "Group Leader" or "admin". I can just remove the widget for anyone that is not a "Group Leader" or "admin", correct?

    My code at the moment looks like

    //* Register widget area for support page. 
    genesis_register_sidebar( array(
    	'id'          => 'new-widget',
    	'name'        => __( 'Support Widget', 'domain' ),
    	'description' => __( 'Add Content Here', 'domain' ),
    ) );
     
    add_action( 'genesis_entry_content', 'your_widget' );
    function your_widget() {
    if ( is_page( 4825 ) and is_user_logged_in() && is_active_sidebar('new-widget') ) {
    genesis_widget_area( 'new-widget', array(
    'before' => '<div class="new-widget widget-area">',
    'after'	 => '</div>',
    		) ); 
     
      }
     
    }

    So my question is how to I display the widget conditionally based on user role? No doubt you have a tutorial already written for that. 🙂

    Jourdain

    October 3, 2014 at 6:39 am #126661
    Brad Dalton
    Participant

    Try

    if ( current_user_can('update_core') ) 
    

    or

    if ( is_admin() )
    

    You will also need to display a login form or redirect to the login page

    Does your code work?

    Never seen and used before in a conditional statement
    I have used AND or &&


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble