Skip to content

Commit

Permalink
Leverage our internal object cache for getting an editorial metadata …
Browse files Browse the repository at this point in the history
…term
  • Loading branch information
danielbachhuber committed Jan 3, 2014
1 parent bedf10e commit 5d74aee
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions modules/editorial-metadata/editorial-metadata.php
Expand Up @@ -625,25 +625,19 @@ function get_editorial_metadata_terms( $filter_args = array() ) {
*/
function get_editorial_metadata_term_by( $field, $value ) {

$term = get_term_by( $field, $value, self::metadata_taxonomy );
if ( ! $term || is_wp_error( $term ) )
return $term;

// Unencode and set all of our psuedo term meta because we need the position and viewable if they exists
$term->position = false;
$term->viewable = false;
$unencoded_description = $this->get_unencoded_description( $term->description );
if ( is_array( $unencoded_description ) ) {
foreach( $unencoded_description as $key => $value ) {
$term->$key = $value;
}
// We used to store the description field in a funny way
if ( isset( $term->desc ) ) {
$term->description = $term->desc;
unset( $term->desc );
}
}
return $term;
if ( ! in_array( $field, array( 'id', 'slug', 'name' ) ) )
return false;

if ( 'id' == $field )
$field = 'term_id';

$terms = $this->get_editorial_metadata_terms();
$term = wp_filter_object_list( $terms, array( $field => $value ) );

if ( ! empty( $term ) )
return array_shift( $term );
else
return false;
}

/**
Expand Down

0 comments on commit 5d74aee

Please sign in to comment.