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 having trouble trying to convert my query_posts loop that is bugging out to a WP_Query, was hoping someone may have some luck looking at it:

This is my old loop:

            <article class="work_items">

            <?php
              query_posts(array( 'post_type' => 'work', 'taxonomy' => 'type', 'posts_per_page' => '-1', 'orderby' => 'title', 'order' => 'ASC' ));
              if ( have_posts() ) : while ( have_posts() ) : the_post();
            ?>

                <aside class="work_item" data-id="id-<?php the_id(); ?>" data-type="<?php $posttags = get_the_tags(); if ($posttags) { foreach ($posttags as $tag) { echo str_replace('-','_',$tag->slug . ' '); } } ?> <?php $posttags = get_the_terms($post->ID, 'type'); if ($posttags) { foreach($posttags as $tag) { echo str_replace('-','_',$tag->slug . ''); } } ?>">

                    <ul>
                        <li>
                            <div class="img_wrap">
                                <?php echo get_the_post_thumbnail($post_id, 'Work Gallery', array('class' => 'lazy',)); ?>
                            </div><!-- /.img_wrap-->

                            <ul class="work_meta">
                                <li class="work_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

                                <?php if ( 'work' == get_post_type() && has_term( 'case-study', 'type') ) { // show 25 characters from the content if the post is a case study ?>

                                     <li class="work_item_content"><?php the_excerpt(25); ?></li>

                                <?php } else { ?>

                                <?php if ( 'work' == get_post_type() && has_term( 'portfolio', 'type') ) { // if the post is a portfolio item show the DESCRIPTION of the image ?>

                                    <li class="work_item_content"><?php echo get_post(get_post_thumbnail_id())->post_content; ?></li>

                                <?php } } ?>

                                <?php
                                    if( has_tag() ) {
                                        // IF THE POST HAS TAGS
                                        the_tags('<li class="work_tags first">', '.</li><li class="work_tags">', '.</li>');
                                        //$articletags = strip_tags(get_the_tag_list('',', ','')); echo $articletags;
                                    }
                                    else {
                                        // IF NO TAGS
                                    }
                                ?>
                            </ul><!-- /.work_meta-->

                            <ul class="work_features">
                                <li class="view_all"><a class="tooltip" title="full details" href="<?php echo the_permalink(); ?>">View All</a></li>
                                <li class="expand"><a rel="prettyPhoto[mixed]" class="expanded tooltip" title="preview" href="#prettyPhoto-<?php the_id(); ?>">Expand</a></li>
                                <li class="lightbox">
                                    <?php if (has_post_thumbnail( $post->ID ) ): ?>
                                    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
                                        <a class="work_lb tooltip" title="view in lightbox" href="<?php echo $image[0]; ?>" rel="prettyPhoto">Lightbox</a>
                                    <?php endif; ?>
                                </li>
                            </ul><!-- /.work_features -->
                        </li>
                    </ul>

                        <aside class="work_expanded" id="prettyPhoto-<?php the_id(); ?>">

                            <?php the_title('<h2>', '</h2>'); ?>

                            <aside id="banner">

                                <?php
                                    $images = get_field('gallery');
                                    if( $images ):
                                ?>
                                    <div class="flexslider">
                                        <ul class="slides">
                                            <?php foreach( $images as $image ): ?>
                                                <li>
                                                    <img class="lazy" src="<?php echo $image['sizes']['Portfolio 1200']; ?>" alt="<?php echo $image['alt']; ?>" />
                                                    <p class="flex-caption"><?php echo $image['caption']; ?></p>
                                                </li>
                                            <?php endforeach; ?>
                                        </ul>
                                    </div>
                                <?php endif; ?>

                            </aside><!-- /#banner-->

                            <aside id="left">

                                <?php get_template_part( 'sidebar', 'work' ); ?>

                            </aside><!-- /#left-->

                            <aside id="right">

                                <article>

                                    <?php the_content(); ?>

                                </article>

                            </aside><!-- /#right-->

                        </aside><!-- /.work_expand-->

                    </aside><!-- /.work_item-->

                <?php endwhile; endif; wp_reset_postdata(); ?>

            </article><!-- /.work_items-->

My attempted new loop:

            <article class="work_items">

            <?php
                $all_work = new WP_Query(array( 'post_type' => 'work', 'tax_query' => array(array('taxonomy' => 'type', 'field' => 'slug', 'terms' => array( 'case study', 'portfolio' ) ) ), 'posts_per_page' => '-1', 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC' ) );
                while ( $all_work->have_posts() ) : $all_work->the_post();
            ?>


                <aside class="work_item" data-id="id-<?php the_id(); ?>" data-type="<?php $posttags = get_the_tags(); if ($posttags) { foreach ($posttags as $tag) { echo str_replace('-','_',$tag->slug . ' '); } } ?> <?php $posttags = get_the_terms($post->ID, 'type'); if ($posttags) { foreach($posttags as $tag) { echo str_replace('-','_',$tag->slug . ''); } } ?>">

                    <ul>
                        <li>
                            <div class="img_wrap">
                                <?php echo get_the_post_thumbnail($post_id, 'Work Gallery', array('class' => 'lazy',)); ?>
                            </div><!-- /.img_wrap-->

                            <ul class="work_meta">
                                <li class="work_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

                                <?php if ( 'work' == get_post_type() && has_term( 'case-study', 'type') ) { // show 25 characters from the content if the post is a case study ?>

                                     <li class="work_item_content"><?php the_excerpt(25); ?></li>

                                <?php } else { ?>

                                <?php if ( 'work' == get_post_type() && has_term( 'portfolio', 'type') ) { // if the post is a portfolio item show the DESCRIPTION of the image ?>

                                    <li class="work_item_content"><?php echo get_post(get_post_thumbnail_id())->post_content; ?></li>

                                <?php } } ?>

                                <?php
                                    if( has_tag() ) {
                                        // IF THE POST HAS TAGS
                                        the_tags('<li class="work_tags first">', '.</li><li class="work_tags">', '.</li>');
                                        //$articletags = strip_tags(get_the_tag_list('',', ','')); echo $articletags;
                                    }
                                    else {
                                        // IF NO TAGS
                                    }
                                ?>
                            </ul><!-- /.work_meta-->

                            <ul class="work_features">
                                <li class="view_all"><a class="tooltip" title="full details" href="<?php echo the_permalink(); ?>">View All</a></li>
                                <li class="expand"><a rel="prettyPhoto[mixed]" class="expanded tooltip" title="preview" href="#prettyPhoto-<?php the_id(); ?>">Expand</a></li>
                                <li class="lightbox">
                                    <?php if (has_post_thumbnail( $post->ID ) ): ?>
                                    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
                                        <a class="work_lb tooltip" title="view in lightbox" href="<?php echo $image[0]; ?>" rel="prettyPhoto">Lightbox</a>
                                    <?php endif; ?>
                                </li>
                            </ul><!-- /.work_features -->
                        </li>
                    </ul>

                        <aside class="work_expanded" id="prettyPhoto-<?php the_id(); ?>">

                            <?php the_title('<h2>', '</h2>'); ?>

                            <aside id="banner">

                                <?php
                                    $images = get_field('gallery');
                                    if( $images ):
                                ?>
                                    <div class="flexslider">
                                        <ul class="slides">
                                            <?php foreach( $images as $image ): ?>
                                                <li>
                                                    <img class="lazy" src="<?php echo $image['sizes']['Portfolio 1200']; ?>" alt="<?php echo $image['alt']; ?>" />
                                                    <p class="flex-caption"><?php echo $image['caption']; ?></p>
                                                </li>
                                            <?php endforeach; ?>
                                        </ul>
                                    </div>
                                <?php endif; ?>

                            </aside><!-- /#banner-->

                            <aside id="left">

                                <?php get_template_part( 'sidebar', 'work' ); ?>

                            </aside><!-- /#left-->

                            <aside id="right">

                                <article>

                                    <?php the_content(); ?>

                                </article>

                            </aside><!-- /#right-->

                        </aside><!-- /.work_expand-->

                    </aside><!-- /.work_item-->

                <?php endwhile; wp_reset_postdata(); ?>

            </article><!-- /.work_items-->

Not sure what I am missing but its not working. When I try to reload the page it just draws a blank... but I am not seeing anything in my error log either. Thanks for any input!

share|improve this question
1  
case study isn't a valid slug, spaces aren't allowed in slugs. –  Milo Sep 24 '13 at 14:51
    
@Milo, thank you.. seem to be having a strange issue. If I take out case-study (updated the slug) and just have portfolio it works as expected (just doesn't display the case studies which makes sense).. if I add both it doesn't work at all.. even tried with ID instead of slug. ` 'tax_query' => array( array( 'taxonomy' => 'type', 'field' => 'id', 'terms' => array( 121, 122 ) ) ), –  Danny Sep 24 '13 at 16:21
    
Actually if I even add the Case Studies to the query by itself by ID or slug it doesn't work (total of 40 items in the database) but the portfolio works fine (5 items) –  Danny Sep 24 '13 at 16:35
    
Hmm, so got it working but the web page times out if the 'posts_per_page' => -1 is set... if I have it at like 30 its fine.. but over that the pages spins for a while then doesn't load. –  Danny Sep 24 '13 at 18:06
    
Try turning WP_DEBUG on, I believe you have a syntax error –  Dan Ștefancu Sep 24 '13 at 19:19
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.