How to add filter in shipment list wp-admin

Note: Please copy and paste this code in functions.php of your current theme.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /* *For this example we are using shipment container *Adding dropdown field */ function custom_assigned_container_filter(){ global $typenow ; $post_type = 'wpcargo_shipment' ; if ( $typenow == $post_type ) { $all_containers = get_shipment_containers(); if ( ! empty ( $all_containers ) ){ $shipment_container = isset( $_GET [ 'shipment_container' ] ) ? $_GET [ 'shipment_container' ] : 0 ; ?> <select id= "wpc-user-branch" name= "shipment_container" > <option value= "" >Select Container</option> <?php foreach ( $all_containers as $container ) { ?><option value= "<?php echo $container->ID; ?>" <?php selected( $shipment_container , $container ->ID ); ?>><?php echo $container ->post_title; ?></option><?php } ?> </select> <?php } } } add_action( 'restrict_manage_posts' , 'custom_assigned_container_filter' ); /* * Include the meta key for filtering of shipments */ function custom_wpcargo_shipment_query_filter( $metakey ){ $metakey [] = 'shipment_container' ; return $metakey ; } add_filter( 'wpcargo_shipment_query_filter' , 'custom_wpcargo_shipment_query_filter' ); |