Bainternet WordPress Consultant
  • WordPress Services
  • Blog
    • Fancy Functions
    • ShortCodes
    • How To’s
  • Plugins
    • Post Editor Zen Coding
    • Advanced Code Editor 2.0
      • other older versions
    • ShortCodes UI
    • User specific Content
    • Simple QR Code
    • Sidebar per user role
    • Simple TOC
    • Post Creation Limits
      • Posts Creation Limits older versions
    • User Ranks
      • Bainternet User Ranks v1.0
    • Custom Category Template
    • Author category
    • Simple Gist Embed
    • WordPress Simple Instant Search Plugin
    • GoTo Redirect
    • Simple Google +1 plugin
  • About Me
    • Donations
  • Contact me

Tax Meta Class – FAQ

Posted on Feb 06, 2012
Ohad Raz
83 Comments
Fancy Functions,How To
  • Share on Facebook.
  • Share on Twitter.
  • Share on Google+
  • Share on LinkedIn
Tax Meta Class - FAQ

About Two weeks ago i posted my Tax Meta Class and ever since then my email inbox is full with few questions about the usage of the class over and over so just to get that out there and free some space in my inbox I’m going to answer these questions here:

QHow to get the term data on the front end?

The class comes with a few helper functions which work just like post meta functions
so is simple as this:

$saved_data = get_tax_meta($term_id,'text_field_id');
echo $saved_data;

QHow to get the term ID?

If you are on a term page (category, tag, or custom) you can use this:

$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
$term_id = $current_term->term_id;

If you know the term name, slug or id then you can use this:

$term = get_term_by( $field, $value, $taxonomy);
$term_id = $term->term_id;

Where $field is name, slug or id
$value is the actual term name, slug or id
and $taxonomy is the name of the taxonomy.

and if you are in a loop then you can use:

//make sure you change <strong>$taxonomy</strong> to the taxonomy name 
$terms = wp_get_post_terms( $post->ID, $taxonomy);
foreach ($terms as $term){
   $term_id = $term->ID;
   //do you term meta stuff here
}

QHow to get the Image?

The image field data is saved as an array of image url as `src` for quick access, and attachment id as `id` so to simlpy display the image you can use:

$saved_data = get_tax_meta($term_id,'image_field_id',true);
echo '<img src="'.$saved_data['src'].'">';

and to get the attachment id of the image use:

$saved_data = get_tax_meta($term_id,'image_field_id',true);
$attachment_id = $saved_data['id'];

QHow to different fields for different taxonomies?

just set the pages field so the config array to the taxonomy you want for each instance of the meta class

$config = array(
  'id' => 'demo_meta_box',
  'title' => 'Demo Meta Box',
  'pages' => array('category'), //<- set this to the taxonomy you want.
  'context' => 'normal', 
  'fields' => array(),
  'local_images' => false,
  'use_with_theme' => false
);

QHow to use in a theme?

just set the use_with_theme field of the config array to true for each instance of the meta class

$config = array(
  'id' => 'demo_meta_box',
  'title' => 'Demo Meta Box',
  'pages' => array('category'),
  'context' => 'normal', 
  'fields' => array(),
  'local_images' => false,
  'use_with_theme' => true  // <- make sure you set this to true if in a theme or a custom folder
);

That is it for now but keep asking and i’ll be happy to help and add your questions.

Incoming search terms:

  • get_tax_meta
  • Tax-Meta-Class
  • tax-meta-class php
  • how to display contanin in return response in image src tax
  • save_post assign tax
  • tax metaclass
  • ефч ьуеф сдфыы

Related posts:

  1. WordPress Taxonomies Extra Fields the easy way
  2. WordPress Categories by year
  3. Conditional tag taxonomy term and its children






Loading comments...
  • About the author

    Ohad Raz

    I'm a WordPress Consultant, a WordPress Developer and a WordPress Freelancer
    Currently in my third year of Software Engineering B.Sce Degree.
    I've been developing Websites and web applications on WordPress for over 5 years.
    I live in Kiryat Gat , Israel.

    • Write an E-Mail
  • Other Methods of contact

    My profile on WordPress Answers

    profile for Bainternet at WordPress, Q&A for WordPress developers and administrators

    • My Code Poet listing

    • My Careers 2.0 Profile

    • My Gravatar.com Profile

    • My About.Me Profile

    • Contact Form

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.





  • Recent Comments

    • WordPress Developer Ohad Raz on Custom taxonomies extra fields
    • WordPress Developer Ohad Raz on Advanced Code Editor 2.0
    • WordPress Developer Gomy on Custom taxonomies extra fields
    • WordPress Developer javier on Advanced Code Editor 2.0
    • WordPress Developer Ohad Raz on Advanced Code Editor 2.0
  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

  • Top Posts & Pages

    • WordPress Taxonomies Extra Fields the easy way
    • Custom taxonomies extra fields
    • how to - WordPress Category Extra Fields
    • How I add a WordPress MetaBox


  • About Me
  • Blog
  • Contact me
  • disclaimer
  • Donations
  • home posts
  • WordPress Services
© 2011 by Bainternet WordPress Consultant