在Wp查询中创建自定义过滤器

时间:2018-11-14 11:18:43

标签: php wordpress

我想为WordPress页面中的帖子创建过滤器栏。

我想使用URL更改和$_GET['parameter']来完成此操作。

它是一个月/年/类别/关键字过滤器。

那是我的代码,有人可以帮助您理解为什么它不起作用以及我应该修复什么。

    $current_url = $_SERVER['REQUEST_URI'];


$count = 0; $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;


if ( !isset($year) && !isset($month) && !isset($category) && !isset($string)){
    $wpb_all_query = new WP_Query(array('post_type'=>'post', 'category_name' => 'Press Release', 'post_status'=>'publish', 'posts_per_page'=>4, 'paged' => $paged ));
}

if( isset($_GET['year']) || isset($_GET['monthnum']) || isset($_GET['category']) || isset($_GET['string']) ){

    if( !isset($_GET['year']) ){
        $year = 'any';
    } else {
        $year = $_GET['year'];
    }

    if( !isset($_GET['monthnum']) ){
        $month = 'any';
    } else {
        $monthnum = $_GET['monthnum'];
    }

    if( !isset($_GET['category']) ){
        $category = 'any';
    } else {
        $category = $_GET['category'];
    }

    if( !isset($_GET['string']) ){
        $string = 'any';
    } else {
        $string = $_GET['string'];
    }



    $wpb_all_query = new WP_Query(array('post_type'=>'post',   'year' => 
    $year, 'monthnum' => $monthnum ,'category_name' => "Press Release, 
    $category",
    '_name__like' => $string , 'post_status'=>'publish', 
    'posts_per_page'=>4, 'paged' => $paged ));

}

0 个答案:

没有答案
相关问题