You should be able to show Category column in the wp-admin / Classifieds and filter by the category after adding the code below in your theme functions.php file
function add_new_advert_column__advert_category($header_text_columns) {
$header_text_columns['advert_category'] = "Category";
return $header_text_columns;
}
add_filter('manage_edit-advert_columns', 'add_new_advert_column__advert_category', 1000);
add_action('manage_advert_posts_columns', 'add_new_advert_column__advert_category', 1000);
function show_order_column__advert_category($name){
global $post;
switch ($name) {
case 'advert_category':
$advert_category = get_the_terms( $post->ID, 'advert_category' );
if( isset( $advert_category[0] ) ) {
$c = $advert_category[0];
echo esc_html( $c->name );
} else {
printf( '—' );
}
break;
default:
break;
}
}
add_action('manage_advert_posts_custom_column','show_order_column__advert_category');
function order_column_register_sortable__advert_category($columns){
$columns['advert_category'] = 'advert_category';
return $columns;
}
add_filter('manage_edit-advert_sortable_columns','order_column_register_sortable__advert_category');
function filter_by__advert_category( $post_type, $which ) {
// Apply this only on a specific post type
if ( 'advert' !== $post_type )
return;
// A list of taxonomy slugs to filter by
$taxonomies = array( 'advert_category' );
foreach ( $taxonomies as $taxonomy_slug ) {
// Retrieve taxonomy data
$taxonomy_obj = get_taxonomy( $taxonomy_slug );
$taxonomy_name = $taxonomy_obj->labels->name;
// Retrieve taxonomy terms
$terms = get_terms( array(
'taxonomy' => $taxonomy_slug,
'hide_empty' => false,
) );
// Display filter HTML
echo "<select name='{$taxonomy_slug}' id='{$taxonomy_slug}' class='postform'>";
echo '<option value="">' . sprintf( esc_html__( 'Show All %s', 'text_domain' ), $taxonomy_name ) . '</option>';
foreach ( $terms as $term ) {
printf(
'<option value="%1$s" %2$s>%3$s</option>',
$term->slug,
( ( isset( $_GET[$taxonomy_slug] ) && ( $_GET[$taxonomy_slug] == $term->slug ) ) ? ' selected="selected"' : '' ),
$term->name
);
}
echo '</select>';
}
}
add_action( 'restrict_manage_posts', 'filter_by__advert_category' , 10, 2);