Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codehooligans/5ee4b88b73dbfa4c5fbe to your computer and use it in GitHub Desktop.
Save codehooligans/5ee4b88b73dbfa4c5fbe to your computer and use it in GitHub Desktop.
Codehooligans.com: Adding Taxonomy Column Data
<?php
add_action( 'init', 'product_init' );
function product_init()
{
// From Part I
register_taxonomy( 'product_packages', 'products',
array( 'hierarchical' => true,
'label' => __('Product Packages'),
'query_var' => false
)
);
// Added from Part II.
// This filter sets up a call to your function which will handle adding (and removing) items
// from the columns array. This filter passes up only one argument. The array of default headers.
add_filter( 'manage_product_packages_columns', 'admin_product_packages_column_headers, 10, 1);
// This filter sets up a call to display the contents of a Product Package row column.
// The filter passes up 3 argument. We only use the second and third arguments.
add_filter( 'manage_product_packages_custom_column', 'admin_product_packages_column_row', 10, 3 );
}
// This function we check the column name then pull in the row data using get_metadata()
function admin_product_packages_column_row( $row_content, $column_name, $term_id )
{
switch($column_name)
{
case 'product_package_active':
$product_package_active = get_metadata('product_packages', $term_id, 'product_package_active', true);
if (!$product_package_active)
$product_package_active = "yes";
return ucfirst($product_package_active);
break;
case 'product_package_unit_price':
return get_metadata('product_packages', $term_id, 'product_package_unit_price', true);
break;
default:
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment