Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to access Custom Taxonomy metadata for all my custom taxonomy terms. The metadata is stored in options like so:

$t_id = $term_id;
    $term_meta = get_option( "taxonomy_$t_id" );
    $cat_keys = array_keys( $_POST['term_meta'] );
    foreach ( $cat_keys as $key ) {
        if ( isset ( $_POST['term_meta'][$key] ) ) {
            $term_meta[$key] = $_POST['term_meta'][$key];
        }
    }
    // Save the option array.
    update_option( "taxonomy_$t_id", $term_meta );

In my attempt to get at each metadata field, I've written the following code, but my array $term_meta is completely empty. Echoing $t_id returns all the IDs successfully, however.

<?php
$taxonomy = 'hhie_artists';
$args = array(
'hide_empty' => 0
);
$terms = get_terms( $taxonomy, $args );
foreach( $terms as $term ) {
    $empty_terms[] = $term;
    $t_id = $term->term_id;
    $term_meta = get_option( 'taxonomy_' . $t_id );
    print_r( $term_meta );
    echo $t_id;
    echo "<br />";
}
?>

As an example, one of the keys in the array would be $term_meta['release_date_meta'] EDIT: Using this on a page template for testing purposes.

share|improve this question
    
Please follow up on the questions you asked, it's an important part of the process on WPSE - see What should I do when someone answers my question? and Why is voting important? for a deeper insight. –  ialocin Apr 8 at 13:30
add comment

1 Answer

Your first code block suggests you're saving your data into a options field named taxonomy_$t_id, but you're trying to get an option named taxonomy_123 in your second code, or whatever the actual term ID is. So you probably getting a return with the value false, which would be the default for get_option(). Have you debugged this? Are you sure you have the meta data saved like you want it to be?

// term ID
$t_id = $term->term_id;
// overly long variable name for the option for demonstration purposes
$term_meta_data_options_name = 'taxonomy_' . $t_id;

// get option with the defined term meta data options name
$term_meta = get_option( $term_meta_data_options_name );

// add/update option with the defined term meta data options name
update_option( $term_meta_data_options_name );
share|improve this answer
    
Expanding upon this, check your wp_options table to see what data is being saved and what the names are. –  Seamus Leahy Dec 16 '13 at 6:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.