【问题标题】:Wordpress restrict categories plugin with DWQA plugin带有 DWQA 插件的 Wordpress 限制类别插件
【发布时间】:2014-05-28 22:36:04
【问题描述】:

我的环境: 使用 DWQA 插件和自定义的限制类别插件与 DWQA 插件一起使用

问题: 我已经定制了“限制类别”插件来为 DWQA 而不是 WP 帖子工作。 现在的问题是,当我以权限从限制类别设置为类别 2 的用户身份登录时,它无法为我显示任何内容。

设置类别过滤器限制类别使用以下代码:

add_filter( 'pre_get_posts', array( &$this, 'posts_query' ) );

    public function posts_query( $query ){          
        if ( $this->cat_list !== '' ) {
            // Build an array for the categories
            $cat_list_array = explode( ',', $this->cat_list );    

            // Make sure the posts are removed by default or if filter category is ran
            if ( ! isset( $_REQUEST['cat'] ) )      
                $query->set( 'category__in', $cat_list_array );
            elseif( isset( $_REQUEST['cat'] ) && $_REQUEST['cat'] == '0' )
                $query->set( 'category__in', $cat_list_array );
        }    

        return $query;  
    }

如果我使用 category__not_in 代替 category__in 那么所有帖子都会显示。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    我已通过如下更改代码解决了这个问题

    public function posts_query( $query ){          
    
            // Build an array for the categories
            $cat_list_array = explode( ',', $this->cat_list );   
    
    
       $taxquery = array(
        array(
            'taxonomy' => 'dwqa-question_category',
            'field' => 'id',
            'terms' => $cat_list_array,
            'operator'=> 'NOT IN'
        )
    );
    
    $query->set( 'tax_query', $taxquery );
    

    【讨论】:

    • 有没有一个选项可以从你的函数中使用 shortcode 和 php 中的 add_shortcode
    猜你喜欢
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多