Advertisement
Guest User

Untitled

a guest
May 29th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1.  
  2.  
  3.  
  4. // Register BGMP Columns
  5. function bgmp_columns_register( $bgmp_columns ) {
  6.     $new_columns[ 'cb' ]        = "<input type=\"checkbox\" />";
  7.     $new_columns[ 'title' ]     = _x( 'Title', 'column name' );
  8.     $new_columns[ 'address' ]   = __( 'Address', 'bgmp' );
  9.     $new_columns[ 'latitude' ]  = __( 'Latitude', 'bgmp' );
  10.     $new_columns[ 'longitude' ] = __( 'Longitude', 'bgmp' );
  11.    
  12.     return $new_columns;
  13. };
  14. add_filter( 'manage_edit-bgmp_columns', 'bgmp_columns_register' );
  15.  
  16. // Display the column content
  17. function bgmp_custom_columns( $bgmp_columns, $post_id ) {
  18.     switch( $bgmp_columns ) {
  19.         case 'address' :
  20.             $address = get_post_meta( $post_id, 'bgmp_address', true );
  21.             if ( $address ) {
  22.                 echo $address;
  23.             } else {
  24.                 echo __( '<em>Not yet set</em>', 'bgmp' );
  25.             }
  26.         break;
  27.         case 'latitude' :
  28.             $address = get_post_meta( $post_id, 'bgmp_latitude', true );
  29.             if ( $address ) {
  30.                 echo $address;
  31.             } else {
  32.                 echo __( '<em>Not yet set</em>', 'bgmp' );
  33.             }
  34.         break;
  35.         case 'longitude' :
  36.             $address = get_post_meta( $post_id, 'bgmp_longitude', true );
  37.             if ( $address ) {
  38.                 echo $address;
  39.             } else {
  40.                 echo __( '<em>Not yet set</em>', 'bgmp' );
  41.             }
  42.         break;
  43.     };
  44. }
  45. add_action( 'manage_bgmp_posts_custom_column', 'bgmp_custom_columns', 10, 2 );
  46.  
  47. // Register the column as sortable
  48. function bgmp_sort( $columns ) {
  49.     $custom = array(
  50.         'address'   => 'address',
  51.         'latitude'  => 'latitude',
  52.         'longitude' => 'longitude'
  53.     );
  54.     return wp_parse_args($custom, $columns);
  55. }
  56. add_filter( 'manage_edit-bgmp_sortable_columns', 'bgmp_sort' );
  57.  
  58. function bgmp_columns_orderby( $vars ) {
  59.     if ( isset( $vars['orderby'] ) && 'address' == $vars['orderby'] ) {
  60.         $vars = array_merge( $vars, array(
  61.             'meta_key' => 'bgmp_address',
  62.             'orderby' => 'meta_value'
  63.         ) );
  64.     }
  65.     if ( isset( $vars['orderby'] ) && 'latitude' == $vars['orderby'] ) {
  66.         $vars = array_merge( $vars, array(
  67.             'meta_key' => 'bgmp_latitude',
  68.             'orderby' => 'meta_value_num'
  69.         ) );
  70.     }
  71.     if ( isset( $vars['orderby'] ) && 'longitude' == $vars['orderby'] ) {
  72.         $vars = array_merge( $vars, array(
  73.             'meta_key' => 'bgmp_longitude',
  74.             'orderby' => 'meta_value_num'
  75.         ) );
  76.     }
  77.     return $vars;
  78. }
  79. add_filter( 'request', 'bgmp_columns_orderby' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement