
Note: Please copy and paste this code in functions.php of your current theme.
/*
*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');