Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Taxonomy based term meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Gijs Jorissen committed Sep 24, 2013
1 parent 2e62e5f commit be220e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
12 changes: 8 additions & 4 deletions classes/meta/term_meta.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ function save_term( $term_id )
// Loop through each meta box
if( ! empty( $this->data ) && isset( $_POST['cuztom'] ) )
{
$data = array();
$values = isset( $_POST['cuztom'] ) ? $_POST['cuztom'] : '';
$data = array();
$values = isset( $_POST['cuztom'] ) ? $_POST['cuztom'] : '';
$taxonomy = $_POST['taxonomy'];

foreach( $this->fields as $id_name => $field )
{
$data[$id_name] = $field->save( $term_id, $values[$field->id], 'term' );
}

update_option( 'term_meta_' . $term_id, $data );
update_option( 'term_meta_' . $taxonomy . '_' . $term_id, $data );
}
}

Expand Down Expand Up @@ -172,7 +173,10 @@ function add_column( $columns )
*/
function add_column_content( $row, $column, $term_id )
{
$meta = get_cuztom_term_meta_by_id( $term_id, $column );
$screen = get_current_screen();
$taxonomy = $screen->taxonomy;

$meta = get_cuztom_term_meta( $term_id, $taxonomy, $column );

foreach( $this->fields as $id_name => $field )
{
Expand Down
24 changes: 1 addition & 23 deletions functions/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function get_cuztom_term_meta( $term, $taxonomy, $key = null )
$term = $term->term_id;
}

$meta = get_option( 'term_meta_' . $term );
$meta = get_option( 'term_meta_' . $taxonomy . '_' . $term );

if( $key ) if( ! empty( $meta[$key] ) ) return $meta[$key]; else return '';

Expand All @@ -66,25 +66,3 @@ function the_cuztom_term_meta( $term, $taxonomy, $key = null )

echo get_cuztom_term_meta( $term, $taxonomy, $key );
}

/**
* Get term meta by the term id
* Can be used if we don;t know the taxonomy for sutre
*
* @param int|string $term Can be the id or the slug of the term
* @param string $key
* @return string
*
* @author Gijs Jorissen
* @since 2.5.3
*/
function get_cuztom_term_meta_by_id( $term_id, $key = null )
{
if( empty( $term_id ) ) return false;

$meta = get_option( 'term_meta_' . $term_id );

if( $key ) if( ! empty( $meta[$key] ) ) return $meta[$key]; else return '';

return $meta;
}

0 comments on commit be220e1

Please sign in to comment.