0

I'm not sure if it's a database or template issue, but on this template page only one post of my Custom Post Types are appearing. There should be at least two.

The page uses an isotope.js script, but disabling it does not alleviate the problem.

The plugin code can found here.

The template code is below:

<?php
/*
Template Name: Exhibitions & Programs
*/
?>
<?php get_header();
    //Set Exhibitions & Programs Query Parameters
if ( false === ( $flagship_exhibitions_query = get_transient( 'flagship_exhibitions_query' ) ) ) {
                // It wasn't there, so regenerate the data and save the transient
                $flagship_exhibitions_query = new WP_Query(array(
                    'post_type' => 'ksasexhibits',
                    'orderby' => 'title',
                    'order' => 'ASC',
                    'posts_per_page' => '-1'));
                    set_transient( 'flagship_exhibitions_query', $flagship_exhibitions_query, 2592000 ); } ?>

<div class="row wrapper radius10">
    <div class="twelve columns">
        <section class="row">

            <div class="five columns copy">
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <h2><?php the_title();?></h2>
                <p><?php the_content(); ?></p>
            <?php endwhile; endif; ?>
            </div>

            <div class="seven columns" id="fields_search" role="search">
                <form action="#">
                    <fieldset class="radius10"> 
                        <?php $exhibits = get_terms('exhibition_type', array(
                            'orderby'       => 'name',
                            'order'         => 'ASC',
                            'hide_empty'    => true,
                            ));

                        $count_exhibits = count($exhibits);
                        if ($count_exhibits > 0) { ?>
                        <div class="row">
                            <h6>Filter by Exhibit Type:</h6>
                        </div>

                        <div class="row filter option-set" data-filter-group="exhibition_type">
                            <div class="button radio"><a href="#" data-filter="" class="selected">View All</a></div>
                            <?php foreach ( $exhibits as $exhibit ) { ?>
                                <div class="button radio"><a href="#" data-filter=".<?php echo $exhibit->slug; ?>"><?php echo $exhibit->name; ?></a></div>
                            <?php } ?>
                        </div>
                    <?php } ?>
                    <div class="row">
                        <h5>Search by keyword:</h5>     
                        <input type="submit" class="icon-search" placeholder="Search by name/keyword" value="&#xe004;" />
                        <input type="text" name="search" value="" id="id_search" aria-label="Search"  /> 
                    </div>
                    </fieldset>
                </form>
            </div>
        </section>

        <section class="row" id="fields_container" role="main">
            <?php while ($flagship_exhibitions_query->have_posts()) : $flagship_exhibitions_query->the_post(); 
        //Pull discipline array (humanities, natural, social)
        $program_types = get_the_terms( $post->ID, 'exhibition_type' );
            if ( $program_types && ! is_wp_error( $program_types ) ) : 
                $program_type_names = array();
                $degree_types = array();
                    foreach ( $program_types as $program_type ) {
                        $program_type_names[] = $program_type->slug;
                        $exhibiton_types[] = $program_type->name;
                    }
                $program_type_name = join( " ", $program_type_names );
                $exhibition_type = join( ", ", $exhibition_types );

            endif; ?>

        <!-- Set classes for isotype.js filter buttons -->
        <div class="six columns mobile-four mobile-field  <?php echo $program_type_name . ' ' . $school_name; ?>">

            <div class="twelve columns field radius10" id="<?php echo $program_name; ?>">
            <a href="<?php echo get_permalink() ?>" title="<?php the_title(); ?>" class="field">
                    <?php if ( has_post_thumbnail()) { ?> 
                        <?php the_post_thumbnail('rss'); ?>
                    <?php } ?>              
                    <h3><?php the_title(); ?></h3>
                </a>

                <div class="row">
                    <div class="twelve columns">
                        <p>
                            <?php if (get_post_meta($post->ID, 'ecpt_location', true)) : ?>
                                        <b>Location:</b>&nbsp;<?php echo get_post_meta($post->ID, 'ecpt_location', true); ?><br>
                                    <?php endif; ?>
                            <?php if (get_post_meta($post->ID, 'ecpt_dates', true)) : ?>
                                        <b>Dates:</b>&nbsp;<?php echo get_post_meta($post->ID, 'ecpt_dates', true); ?><br>
                                    <?php endif; ?>
                            <?php if (get_post_meta($post->ID, 'ecpt_description', true)) : ?>
                                        <b>Description:</b>&nbsp;<?php echo get_post_meta($post->ID, 'ecpt_description', true); ?><br>
                                    <?php endif; ?>
                        </p>


                    </div>
                </div>
            </div>
        </a>
    </div>
    <?php endwhile; ?>

    <div class="row" id="noresults">
            <div class="four columns centered">
                <h3> No matching results</h3>
            </div>
    </div>
        </section>

    </div>
</div>
 <!-- End content wrapper -->
    <script src="<?php echo get_template_directory_uri() ?>/assets/javascripts/page.exhibits.js"></script>  <?php get_footer(); ?>

2 Answers 2

-1

try changing the value of

'posts_per_page' => '-1'

this is what's probably messing up your query,

if you want two try setting it to :

'posts_per_page' => '2'

also try to comment it out.....


I think it's quite self-explanatory, but to really understand wp-query read the Codex ref..

5
  • 1
    Please add an explanation to your answer: why could that solve the problem?
    – fuxia
    Commented Oct 17, 2014 at 19:48
  • extended the answer
    – maioman
    Commented Oct 17, 2014 at 19:56
  • I've tried that to no avail either. Thanks for the suggestion though.
    – timmyg
    Commented Oct 17, 2014 at 19:56
  • According to the Codex for WP Query, "Use 'posts_per_page'=>-1 to show all posts".
    – Gabriel
    Commented Oct 17, 2014 at 20:01
  • usually wp_query and multiple loops have another syntax... try taking a look at multiple loops in the codex
    – maioman
    Commented Oct 17, 2014 at 20:02
-1

I found that if I removed the get_transient and set_transient functions from lines 8 & 15 then the CPT's loaded just fine.

Thanks for the help everyone!

3
  • You've solved the problem by removing the caching components of the code. That is not the best of solutions.
    – s_ha_dum
    Commented Oct 20, 2014 at 15:09
  • Okay; will it cause problems further down the road?
    – timmyg
    Commented Oct 20, 2014 at 17:49
  • It may effect performance
    – s_ha_dum
    Commented Oct 20, 2014 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.