Thesis Framework and Custom Post Types

First time creating/implementing custom post types in Thesis, not first time using custom post types.

I used the Reed Write plugin to create the custom post types. The site is using Thesis 1.8.5.

Read More

On the following page (http://www.snyderleadership.com/press-releases/) I have the main content getting dropped in with the contents of the custom post type after it.

I used the custom_functions.php file to create a custom page template and call the db for the contents of the custom post type. Here is my code:

/* CUSTOM PRESS RELEASE TEMPLATE - ADDED by BRETT ATKIN */

function press_releases_page() {
if (is_page('press-releases') || is_page('583')) { ?>

<div id="content">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="post_box">
    <div class="headline_area"><h1><?php the_title(); ?></h1></div>
    <div class="format_text">
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php endif ?>
    <?php
        $original_query = $wp_query;
        $wp_query = null;

        $args = array (
        'post_type' => 'press-release',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'orderby' => 'date',
        'order' => 'DESC'
        );
        $wp_query = new WP_Query($args);
        ?>
    <div id="press-releases">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <div id="press-wrapper">
            <div id="press-image">
                <?php echo wp_get_attachment_image(get_post_meta($post->ID, 'release_image', true)); ?>
            </div><!-- end press-image div -->
            <div id="press-information">
                <p class="press-date"><?php echo get_post_meta($post->ID, 'release_date', true); ?></p>
                <p class="press-link"><a href="<?php echo get_post_meta($post->ID, 'release_link', true); ?>" target="_blank"><?php echo get_post_meta($post->ID, 'release_title', true); ?></a></p>
                <p class="press-author"><?php echo get_post_meta($post->ID, 'release_author', true); ?></p>
            </div><!-- end press-information div -->
            <div style="clear:both;"></div>
        </div><!-- end press-wrapper div -->
        <?php endwhile; endif; wp_reset_postdata(); ?>
    </div><!-- end press-releases div -->
    </div>
    </div>
    </div><!-- end content -->
    <?php echo thesis_sidebars(); ?>
<?php } }

add_action('thesis_hook_custom_template', 'press_releases_page');

It seems like everything is working correctly, just not pulling in the data for the custom post type.

Having done this on other sites (using custom themes), I’m not sure if I did something wrong here or if it is a Thesis issue.

Any help would be great.

Thanks

Brett

Related posts

Leave a Reply

2 comments

  1. Here is the final working code. Thanks to the help from of a local WP Guru friend and maiorano84. We didn’t figure out the cause, but we did fine a solution.

    function press_releases_page() {
    if (is_page('press-releases') || is_page('583')) { ?>
    
    <div id="content">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <div class="post_box">
        <div class="headline_area"><h1><?php the_title(); ?></h1></div>
        <div class="format_text">
        <?php the_content(); ?>
        <?php endwhile; ?>
        <?php endif ?>
    
        <?php
            $original_query = $wp_query;
            $wp_query = null;
    
            $args = array (
            'post_type' => 'press-release',
            'post_status' => 'publish',
            'posts_per_page' => -1,
            'orderby' => 'date',
            'order' => 'DESC'
            );
            $wp_query = new WP_Query($args);
        ?>
    
        <div id="press-releases">
            <?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
            <?php $results = get_post_custom(); ?>
            <div id="press-wrapper">
                <div id="press-image"><?php echo wp_get_attachment_image($results['release_image'][0] ); ?></div><!-- end press-image div -->
                <div id="press-information">
                    <p class="press-date"><?php echo $results['release_date'][0] ?></p> 
                    <p class="press-link"><a href="<?php echo $results['release_link'][0] ?>" target="_blank"><?php echo $results['release_title'][0] ?></a></p>
                    <p class="press-author"><?php echo $results['release_author'][0] ?></p>
                </div><!-- end press-information div -->
                <div style="clear:both;"></div>
            </div><!-- end press-wrapper div -->
            <?php endwhile; endif; wp_reset_query(); wp_reset_postdata(); ?>
        </div><!-- end press-releases div -->
        </div>
        </div>
        </div><!-- end content -->
        <?php echo thesis_sidebars(); ?>
    <?php } }
    
    remove_action('thesis_hook_custom_template', 'thesis_custom_template_sample');
    add_action('thesis_hook_custom_template', 'press_releases_page');
    
  2. Try changing this:

    <div id="press-releases">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div id="press-wrapper">
    

    To this:

    <div id="press-releases">
    <?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    <div id="press-wrapper">
    

    UPDATE:

    The only other thing I can see is that you’re not resetting your post data, and that the $wp_query variable is actually a WordPress Global. Try using the reset functions and changing your WP_Query instance name like this:

    <?php
        wp_reset_query();
        wp_reset_postdata();
    
        $args = array (
        'post_type' => 'press-release',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'orderby' => 'date',
        'order' => 'DESC'
        );
        $query = new WP_Query($args);
        ?>
    <div id="press-releases">
        <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
    

    UPDATE 2:

    Now that you have your wrappers being written to your document, you need to normalize your information. Try to avoid using Metadata instead of normal post attributes. I imagine your metadata ‘release_image’ is a link to an image somewhere on your server:

    <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
    ?>
        <div id="press-wrapper">
            <div id="press-image">
                <img src="<?php echo get_post_meta(get_the_ID(), 'release_image', true); ?>" />
            </div><!-- end press-image div -->
            <div id="press-information">
                <p class="press-date"><?php echo the_date(); ?></p>
                <p class="press-link"><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></p>
                <p class="press-author"><?php the_author(); ?></p>
            </div><!-- end press-information div -->
            <div style="clear:both;"></div>
        </div><!-- end press-wrapper div -->
        <?php endwhile; endif; wp_reset_postdata(); ?>