【问题标题】:Wordpress disable private posts linksWordpress 禁用私人帖子链接
【发布时间】:2016-05-10 03:15:28
【问题描述】:

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

未登录的用户可以点击帖子并访问它。

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

【问题讨论】:

  • 嘿,你只需像 is_user_logged_in() 那样输入检查;
  • 私人是你的类别?
  • Erick G.“这句话错了吗,未登录”

标签: wordpress private posts


【解决方案1】:

将此代码放入您的 function.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');

【讨论】:

  • 你认为wp_redirect 会在the_content 过滤器上工作吗?
  • 那么请发表你的答案
  • 已经是一个很好的解决方案,如果你能显示一个对话框可能是一个java调用“比赛还没有进行”就完美了
  • 如果您有更好的解决方案,请与我们分享。
猜你喜欢
  • 2014-09-14
  • 1970-01-01
  • 2016-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 1970-01-01
  • 2013-08-21
相关资源
最近更新 更多