You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求可针对特定用户限制WordPress文章/页面列表可见性的插件

Got it, let's solve this problem for you. The core issue with the User Specific Content plugin is that it only hides post content—not the actual post entries in archives, search results, or even the dashboard post list. Here are a few reliable ways to make sure only assigned users see their posts everywhere:

1. Use a Dedicated User Restriction Plugin

These tools are built to handle exactly what you need, with zero custom code required:

  • Members (Free):This plugin lets you set granular content permissions, and crucially, it filters post lists automatically. When editing a post/page, look for the "Content Permissions" metabox, select "USER 1" as the allowed user, and save. Other users (like USER 2) won't see this post in any front-end lists or their dashboard post manager (admins still get full access).
  • Restrict Content Pro (Premium):If you need advanced features like paid content tiers or user groups, this plugin also supports per-user post restrictions and fully removes unauthorized posts from all lists. It's paid, but Members will cover your basic needs perfectly.

2. Custom Code Solution (No Extra Plugins)

If you prefer to avoid adding another plugin, add this code to your theme's functions.php file or a custom plugin:

function filter_posts_for_assigned_user( $query ) {
    // Skip admin queries for site admins (so they can still see all content)
    if ( is_admin() && current_user_can( 'manage_options' ) ) {
        return $query;
    }

    $current_user = wp_get_current_user();
    // Only apply filter to logged-in non-admin users
    if ( $current_user->ID && !current_user_can( 'manage_options' ) ) {
        // Filter posts where a custom field 'allowed_user' matches the current user's login
        $query->set( 'meta_key', 'allowed_user' );
        $query->set( 'meta_value', $current_user->user_login );
        $query->set( 'meta_compare', '=' );
        // Include both posts and pages (remove if you only need posts)
        $query->set( 'post_type', array( 'post', 'page' ) );
    }
    return $query;
}
add_action( 'pre_get_posts', 'filter_posts_for_assigned_user' );

How to use this code:

  • When editing a post/page, add a custom field (enable it via the "Options" dropdown in the top-right of the editor if you don't see it) with:
    • Name: allowed_user
    • Value: The login name of the user who should see this content (e.g., USER 1)
  • This code will ensure the current user only sees posts/pages where the allowed_user field matches their login—across front-end lists, search results, and their dashboard post list.

Bonus: Allow multiple users per post

If you need to grant access to multiple users for a single post, modify the code to use an array of user logins:

// Replace the meta lines with this
$query->set( 'meta_key', 'allowed_users' );
$query->set( 'meta_value', $current_user->user_login );
$query->set( 'meta_compare', 'LIKE' );

Then set the custom field allowed_users to a comma-separated list of logins (e.g., USER 1,USER 3).

内容的提问来源于stack exchange,提问作者E. Davis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:35:58