Skip to content

Instantly share code, notes, and snippets.

@jdsteinbach
Last active February 8, 2016 18:31
Show Gist options
  • Select an option

  • Save jdsteinbach/fe79dc83ab149efbc290 to your computer and use it in GitHub Desktop.

Select an option

Save jdsteinbach/fe79dc83ab149efbc290 to your computer and use it in GitHub Desktop.
<?php
if ( ! function_exists( 'get_color_cpts' ) ) {
function get_color_things( $color, $cpt ) {
$this_query_args = array(
'post_type' => $cpt,
'numberposts' => -1 // or whatever # you want if you need this limited
'orderby' => 'date',
'order' => 'DESC' // if you need to change order do that here
'tax_query' => array(
array(
'taxonomy' => 'colors',
'field' => 'slug',
'terms' => $color
)
)
);
$this_query = new WP_Query( $this_query_args );
wp_reset_postdata();
return $this_query->posts;
}
}
$post_types = array( 'plates', 'bowls', 'cups' );
foreach ( $post_types as $pt ) {
$$pt = get_color_things( $post->post_name, $pt );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment