/ Published in: PHP
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
// Change the columns for the edit CPT screen
function change_columns( $cols ) {
'cb' => '<input type="checkbox" />',
'url' => __( 'URL', 'trans' ),
'referrer' => __( 'Referrer', 'trans' ),
'host' => __( 'Host', 'trans' ),
);
return $cols;
}
add_filter( "manage_<CPT>_posts_columns", "change_columns" );
function custom_columns( $column, $post_id ) {
switch ( $column ) {
case "url":
$url = get_post_meta( $post_id, 'url', true);
echo '<a href="' . $url . '">' . $url. '</a>';
break;
case "referrer":
$refer = get_post_meta( $post_id, 'referrer', true);
echo '<a href="' . $refer . '">' . $refer. '</a>';
break;
case "host":
echo get_post_meta( $post_id, 'host', true);
break;
}
}
add_action( "manage_posts_custom_column", "custom_columns", 10, 2 );
// Make these columns sortable
function sortable_columns() {
'url' => 'url',
'referrer' => 'referrer',
'host' => 'host'
);
}
add_filter( "manage_edit-<CPT>_sortable_columns", "sortable_columns" );
// Filter the request to just give posts for the given taxonomy, if applicable.
function taxonomy_filter_restrict_manage_posts() {
global $typenow;
// If you only want this to work for your specific post type,
// check for that $type here and then return.
// This function, if unmodified, will add the dropdown for each
// post type / taxonomy combination.
$filters = get_object_taxonomies( $typenow );
foreach ( $filters as $tax_slug ) {
$tax_obj = get_taxonomy( $tax_slug );
'show_option_all' => __('Show All '.$tax_obj->label ),
'taxonomy' => $tax_slug,
'name' => $tax_obj->name,
'orderby' => 'name',
'selected' => $_GET[$tax_slug],
'hierarchical' => $tax_obj->hierarchical,
'show_count' => false,
'hide_empty' => true
) );
}
}
}
add_action( 'restrict_manage_posts', 'taxonomy_filter_restrict_manage_posts' );
Comments
 Subscribe to comments
                    Subscribe to comments
                
                