ttt-logo 超方科技 tesseract technology tianjin

WordPress 给自定义post type 添加筛选条件

WordPress 给自定义post type 添加筛选条件

 

add_action( 'restrict_manage_posts', 'my_restrict_manage_posts' );
function my_restrict_manage_posts() {
	global $typenow;
	$taxonomy = $typenow.'_type';
	if( $typenow != "page" && $typenow != "post" ){
		$filters = array($taxonomy);
		foreach ($filters as $tax_slug) {
			$tax_obj = get_taxonomy($tax_slug);
			$tax_name = $tax_obj->labels->name;
			$terms = get_terms($tax_slug);
			echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
			echo "<option value=''>Show All $tax_name</option>";
			foreach ($terms as $term) { echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>'; }
			echo "</select>";
		}
	}
}

标签TAGS

与标签相关的文章

最新文章

热门文章

其他文章

Sign up for our Newsletter

iPhone

Lorem ipsum dolor sit amet

MacBook

Sed do eiusmod tempor incididunt

iPad

Tempor incididunt ut labore et dolore