Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Register BGMP Columns
- function bgmp_columns_register( $bgmp_columns ) {
- $new_columns[ 'cb' ] = "<input type=\"checkbox\" />";
- $new_columns[ 'title' ] = _x( 'Title', 'column name' );
- $new_columns[ 'address' ] = __( 'Address', 'bgmp' );
- $new_columns[ 'latitude' ] = __( 'Latitude', 'bgmp' );
- $new_columns[ 'longitude' ] = __( 'Longitude', 'bgmp' );
- return $new_columns;
- };
- add_filter( 'manage_edit-bgmp_columns', 'bgmp_columns_register' );
- // Display the column content
- function bgmp_custom_columns( $bgmp_columns, $post_id ) {
- switch( $bgmp_columns ) {
- case 'address' :
- $address = get_post_meta( $post_id, 'bgmp_address', true );
- if ( $address ) {
- echo $address;
- } else {
- echo __( '<em>Not yet set</em>', 'bgmp' );
- }
- break;
- case 'latitude' :
- $address = get_post_meta( $post_id, 'bgmp_latitude', true );
- if ( $address ) {
- echo $address;
- } else {
- echo __( '<em>Not yet set</em>', 'bgmp' );
- }
- break;
- case 'longitude' :
- $address = get_post_meta( $post_id, 'bgmp_longitude', true );
- if ( $address ) {
- echo $address;
- } else {
- echo __( '<em>Not yet set</em>', 'bgmp' );
- }
- break;
- };
- }
- add_action( 'manage_bgmp_posts_custom_column', 'bgmp_custom_columns', 10, 2 );
- // Register the column as sortable
- function bgmp_sort( $columns ) {
- $custom = array(
- 'address' => 'address',
- 'latitude' => 'latitude',
- 'longitude' => 'longitude'
- );
- return wp_parse_args($custom, $columns);
- }
- add_filter( 'manage_edit-bgmp_sortable_columns', 'bgmp_sort' );
- function bgmp_columns_orderby( $vars ) {
- if ( isset( $vars['orderby'] ) && 'address' == $vars['orderby'] ) {
- $vars = array_merge( $vars, array(
- 'meta_key' => 'bgmp_address',
- 'orderby' => 'meta_value'
- ) );
- }
- if ( isset( $vars['orderby'] ) && 'latitude' == $vars['orderby'] ) {
- $vars = array_merge( $vars, array(
- 'meta_key' => 'bgmp_latitude',
- 'orderby' => 'meta_value_num'
- ) );
- }
- if ( isset( $vars['orderby'] ) && 'longitude' == $vars['orderby'] ) {
- $vars = array_merge( $vars, array(
- 'meta_key' => 'bgmp_longitude',
- 'orderby' => 'meta_value_num'
- ) );
- }
- return $vars;
- }
- add_filter( 'request', 'bgmp_columns_orderby' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement