本功能一般用于wordpress后台展示出所有文章后,通过分类进行筛选出相关文章。
那么,要做这个功能的时候,想必您已经创建了自定义文章类型和相关分类了。
即:custom post type 和 taxonomy
 
为了更好得看懂下面的代码,在这里假设:
custom post type为carryon_jobs。(注:这个就是一个自定义文章类型的名字,具体要按您实际的自定义文章类型的名称来操作。)
taxonomy为jobs_category。(注:这个就是一个自定义文章分类的名字,具体要按您实际的自定义文章分类的名称来操作。)
 
实现这个功能所用的代码为:

//此部分功能是生成分类下拉菜单
add_action('restrict_manage_posts','my_post_type_filter',10,2);
function my_post_type_filter($post_type, $which){
    if('carryon_jobs' !== $post_type){
      return; //check to make sure this is your cpt
    }
    $taxonomy_slug = 'jobs_category';
    $taxonomy = get_taxonomy($taxonomy_slug);
    $selected = '';
    $request_attr = 'jobs_category'; //this will show up in the url
    if ( isset($_REQUEST[$request_attr] ) ) {
      $selected = $_REQUEST[$request_attr]; //in case the current page is already filtered
    }
    wp_dropdown_categories(array(
      'show_option_all' =>  __("Show All"),
      'taxonomy'        =>  $taxonomy_slug,
      'name'            =>  $request_attr,
      'orderby'         =>  'name',
      'selected'        =>  $selected,
      'hierarchical'    =>  true,
      'depth'           =>  5,
      'show_count'      =>  true, // Show number of post in parent term
      'hide_empty'      =>  false, // Don't show posts w/o terms
    ));
  }
//此部分功能是列出指定分类下的所有文章
add_filter( 'parse_query', 'perform_filtering' );
function perform_filtering( $query ) {
	$qv = & $query->query_vars;
	if ( ( $qv[ 'jobs_category' ] ) && is_numeric( $qv[ 'jobs_category' ] ) ) {
		$term = get_term_by( 'id', $qv[ 'jobs_category' ], 'jobs_category' );
		$qv[ 'jobs_category' ] = $term->slug;
	}
}

 
那么,以上两组函数及hook都是在wordpress官网有所介绍的。

参考:

restrict_manage_posts的用法:

请参阅:https://developer.wordpress.org/reference/hooks/restrict_manage_posts/

parse_query的用法:

请参阅:https://codex.wordpress.org/Plugin_API/Action_Reference/parse_query