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 am using short codes in theme for grid display. Code only considers category ids. I also want to add custom taxonomies so it give output as both category posts as well as custom taxonomy posts.

    function five_col( $atts ) {
    extract( shortcode_atts( array(
        'cats' => '1',
        'num' => '2',
        'offset' => '0',
    ), $atts ) );
    $sq = new WP_Query(array('posts_per_page' => $num, 'post_status' => 'publish', 'order' => 'desc', 'ignore_sticky_posts' => 1, 'cat' => $cats, 'offset' => $offset));
    if ($sq->have_posts()) :
    $count = 1;
    $col = 5;
    $out = '<ul class="three_col">';
    while ($sq->have_posts()) : $sq->the_post();
                $thumbClass = ($count == $col) ? 'last' : '';
                    $permalink = get_permalink();
                    $title = get_the_title();
                    $bloginfo = get_template_directory_uri();
                    if ( has_post_thumbnail()) {
                        $img_src = wp_get_attachment_image_src( get_post_thumbnail_id($GLOBALS['post']->ID), '');
                        $thumbnail = $img_src[0];
                    }
                    else $thumbnail = '';
                    $default_thumb = $bloginfo.'/images/post_thumb.jpg';
                    $thumbnail = ( $thumbnail == '' ) ? $default_thumb : $thumbnail;
                        $format = '<li class="'.$thumbClass.'"><a href="%3$s" title="%4$s"><div class="img_thumb"><img src="%1$s/scripts/timthumb.php?src=%2$s&amp;w=70&amp;h=130&amp;zc=1&amp;q=100" alt="%4$s"/></div><h5><a href="%3$s" rel="bookmark" title="' . __( 'Permanent Link to %4$s', 'volt' ) . '">%4$s</a></h5></li></a>';
                        $out .= sprintf ($format, $bloginfo, $thumbnail, $permalink, $title );
            $count++;
            if($count > $col){
            $col = $col + 5;
            $out .= '<li class="clear"></li>';
                }
                endwhile;
                $out .= '</ul>';
                return $out;
        endif;
    wp_reset_postdata(); // Restore global post data stomped by the_post().
}
share|improve this question
add comment

1 Answer

Not sure if is this, but you can add taxonomies in query:

new WP_Query(array('posts_per_page' => $num, 'post_status' => 'publish','taxonomy' => $taxonomy)); 

You can filter by term with $taxonomy => $term:

$taxonomy = 'seasons';
$term = 'spring'
/* $terms = array('summer','winter')  an array */

new WP_Query(array('posts_per_page' => $num, 'post_status' => 'publish',$taxonomy => $term)); 

More on WP_Query

Note: taxonomies and terms are not the same thing :)

share|improve this answer
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.