代码之家  ›  专栏  ›  技术社区  ›  barabba58

Wordpress禁用私人帖子链接

  •  -1
  • barabba58  · 技术社区  · 10 年前

    我有一个体育比赛网站。我可以创建未来比赛的日历,然后将帖子状态设置为“私人”。

    用户 不是 登录后可以点击帖子并访问它。

    如何禁用未登录用户的帖子链接?

    1 回复  |  直到 10 年前
        1
  •  0
  •   Vasim Shaikh    10 年前

    将此代码放入函数中。php文件。

    function getPrivatePostMatch()
    {
        global $post;
        $status = get_post_status( $post->ID );
        if( $status == "private" )
        {
            wp_redirect( home_url() );  // you can add your page url here
            exit;
        }
    }
    add_action('template_redirect','getPrivatePostMatch');
    
    推荐文章