IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
  1. Home
  2. Technology
  3. CMS
  4. Wordpress
  5. Restrict guest to view only blog posts

Restrict guest to view only blog posts

2019-03-01 794 Views 0 Like 0 Comments

Restrict guest to view only blog posts, instead of all public posts.

blog posts

1. Add 'blog' tag to all blog posts.

2. Add pre_get_posts action to restrict the query.

function show_only_blog( $query ) {
    if ( is_user_logged_in() ) return;
	
    $tax_query = array(
        array(
            'taxonomy' => 'post_tag',
            'field'    => 'slug',
            'terms'    => 'blog',
        ),
    );
    $query->set( 'tax_query', $tax_query );
}

add_action( 'pre_get_posts', 'show_only_blog' );

Loading

error
fb-share-icon
Tweet
fb-share-icon
IT Team
Author: IT Team

Tags: None
Last updated:2019-03-01

IT Team

This person is lazy and left nothing

Like
< Previous
Next >

Comments

Cancel reply
Newest Hotspots Random
Newest Hotspots Random
Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
New team member have no permission to access - Dynamics 365 WP Plugin "User Specific Content" review Null values concerns in SQL Server Special Links in HTML Extend some useful string functions in C# Make up table definition with [yr-mth] columns and column list
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

This site is supported by Hostlike.com