Skip to content

Instantly share code, notes, and snippets.

@astockwell
Last active August 29, 2015 13:57
Show Gist options
  • Save astockwell/9360602 to your computer and use it in GitHub Desktop.
Save astockwell/9360602 to your computer and use it in GitHub Desktop.
<?php
/*
* Reference
*
* Term object keys:
* [term_id, name, slug, term_group, term_taxonomy_id, taxonomy, description, parent]
*
*/
/*
* Scope: Global
*/
// Get all terms in a taxonomy
$terms = get_terms( 'taxonomy (string|array)', array('orderby' => 'menu_order') );
// Get a term object from id/slug/name
$term = get_term_by( 'field ("id"|"slug"|"name")', 'value (string|int)', 'taxonomy (string)' );
// Get term archive url
$url = get_term_link( $term (term object|term ID|term slug), $taxonomy );
/*
* Scope: Post
*/
// Get post terms
$terms = wp_get_post_terms( $post->ID, 'taxonomy (string|array)' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment