snippets

Template tags

Display the terms that are associated with the post (or posttype) for a specific taxonomy (taxonomy-name) <?php  the_terms( $post->ID, 'taxonomy-name', '', ', ', '' ); ?> or <?php echo get_the_term_list( $post->ID, 'taxonomy-name', '', '<br /> ', '' ); ?> without hyperlink <?php $terms = get_the_terms( $post->ID, 'taxonomy-name') ;$term_list = array_pop($terms)->name ; foreach( $terms as $os ) {    $term_list .= ", " . $os->name ; } echo $term_list ; ?> excluding a specific term <?php $terms = get_the_terms( $post->ID, 'taxonomy-name' ); foreach ( $terms as $term  ) { if($term->term_id != 104) { // the term ID you want to exclude $term_IDs[] = $term->term_id; } } $terms = implode(',', $term_IDs); ?> <ul> <?php wp_list_categories('taxonomy=project-status&title_li=&include='.$terms); ?> </ul>
Display current term on archives <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?>

Conditionals

Basic conditional with different options <?php if ( in_category('saving')) { ?> STUFF 1 <?php } else if ( in_category('housing')) { ?> STUFF 2 <?php } else { ?> STUFF 3 <?php } ?> ACF Conditional <?php if (get_field('field_name') ) { ?> STUFF <?php } else if (get_field('field_name2')) { ?> STUFF 2 <?php } else { ?> STUFF 3 <?php } ?> Taxonomy conditional – if post has a specific term <?php if ( pa_in_taxonomy( 'taxonomy-name', 'term-1' )) { ?> STUFF 1 <?php } else if ( pa_in_taxonomy( 'taxonomy-name', 'term-2' )) { ?> STUFF 2 <?php } else { ?> STUFF 3 <?php } ?>
http://alex.leonard.ie/2011/06/30/wordpress-check-if-post-is-in-custom-taxonomy/

Loop queries

Show all post-types that have a specific term <?php query_posts( array( 'post_type' => 'post-type-name', 'taxonomy-name' => 'term-name' ) );  if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> POSTS <?php endwhile; endif; wp_reset_query(); ?> Show all posts-types and order those posts by a specific term (alphabetical) <?php $posts = query_posts('post_type=post-type-name&orderby=taxonomy-name&order=asc&posts_per_page=-1'); if (have_posts()) : while (have_posts()) : the_post(); ?> POSTS <?php endwhile; endif; ?>

General

oEmbed with ACF <?php echo apply_filters('the_content', get_field('field-name')); ?> Inserts the URL for your child theme directory. use this to reference the URL’s of theme images, CSS etc <?php echo get_stylesheet_directory_uri(); ?> Display a random block of code <?php $Block_ID = rand(1,4); ?> <?php if ($Block_ID == 1) { ?> STUFF 1 <?php } ?> <?php if ($Block_ID == 2) { ?> STUFF 2 <?php } ?> <?php if ($Block_ID == 3) { ?> STUFF 3 <?php } ?> <?php if ($Block_ID == 4) { ?> STUFF 4 <?php } ?>   Query with ACF

<?php $args = array( 'posts_per_page' => 1, 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'number', 'field' => 'slug', 'terms' => array( get_field('field_name') ) ) ) ); query_posts( $args ); while ( have_posts() ): the_post(); // do stuff here ?>
move share buttons

functions.php:
function remove_sharedaddy() {
remove_filter( 'the_content', 'sharing_display',19 );
remove_filter( 'the_excerpt', 'sharing_display',19 );
if ( class_exists( 'Jetpack_Likes' ) ) {
remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 );
}
}
add_action( 'loop_start', 'remove_sharedaddy' );

page template:
<?php echo sharing_display(); ?>