0

I have three page templates, homepage, documentary, and corporate, each using the same CPT WP_query code with only the category name changed for each respectively. The homepage works fine, pulling and showing the correct category of my CPT. The other two do not work.

Here is a snippet of the code for the homepage:

<?php
/*
Template Name: Homepage Reels
*/

/*
@package _tk
*/

get_header(); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<div class="entry-content">

    <div class="container-fluid">

    <?php $args = array( 'post_type' => 'films',
                         'tax_query' => array(
                                            array(
                                            'taxonomy' => 'film-type',
                                            'field' => 'slug',
                                            'terms' => 'homepage',
                                            )
                                        ),
                         'posts_per_page' => '-1', );
          $the_query = new WP_Query( $args ); ?>

<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php /* Get the current post ID. */
                    $post_id = get_the_ID();
                  /* If we have a post ID, proceed. */
                    if ( !empty( $post_id ) ) { ?>

                    <div class="film_wrap col-md-4">

                        <?php // <h2 class="film_title"><?php the_title(); ?><?php //</h2> ?>

                        <?php $videourl = get_post_meta( $post_id, 'film_embed', true );
                              if ( $videourl != '' ) {
                                echo wp_oembed_get( $videourl ); 
                              } ?>

                        <?php if ( get_post_meta( $post_id, 'film_textarea', true ) ) : ?>
                            <div class="film_description">
                                <p><?php echo get_post_meta( $post_id, 'film_textarea', true ); ?></p>
                            </div>
                        <?php endif; ?>

                    </div>

                    <?php } else { ?>

                        <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>

                    <?php } ?>

        <?php wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', '_tk' ),
            'after'  => '</div>',
        ) ); ?>

    <?php endwhile; ?>
    <?php endif; ?>

and the documentary template:

<?php
/*
Template Name: Documentary Reels
*/

/*
@package _tk
*/

get_header(); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<div class="entry-content">

    <div class="container-fluid">

    <?php $args = array( 'post_type' => 'films',
                         'tax_query' => array(
                                            array(
                                            'taxonomy' => 'film-type',
                                            'field' => 'slug',
                                            'terms' => 'documentary',
                                            )
                                        ),
                         'posts_per_page' => '-1', );
          $the_query = new WP_Query( $args ); ?>

<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<?php /* Get the current post ID. */
                    $post_id = get_the_ID();
                  /* If we have a post ID, proceed. */
                    if ( !empty( $post_id ) ) { ?>

                    <div class="film_wrap col-md-4">

                        <?php // <h2 class="film_title"><?php the_title(); ?><?php //</h2> ?>

                        <?php $videourl = get_post_meta( $post_id, 'film_embed', true );
                              if ( $videourl != '' ) {
                                echo wp_oembed_get( $videourl ); 
                              } ?>

                        <?php if ( get_post_meta( $post_id, 'film_textarea', true ) ) : ?>
                            <div class="film_description">
                                <p><?php echo get_post_meta( $post_id, 'film_textarea', true ); ?></p>
                            </div>
                        <?php endif; ?>

                    </div>

                    <?php } else { ?>

                        <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>

                    <?php } ?>

        <?php wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', '_tk' ),
            'after'  => '</div>',
        ) ); ?>

    <?php endwhile; ?>
    <?php endif; ?>

I have no errors via WP_DEBUG. Here is the testing site: http://thegallerymusic.com/test/

Can't think of what could possibly be allowing homepage to work, but causing the documentary/corporate templates to NOT work. Any ideas?

  • 1
    what doesn't work? It doesn't show anything? Also, can you add the names of the files? – Tomás Cot Sep 11 '14 at 20:59
  • Yea, on the corporate and documentary pages nothing shows up. The names of the template files are: homepage.php, corporate.php, and documentary.php. What's also interesting is that the archive page for the custom post type (thegallerymusic.com/test/films) populates only six of the posts(two on page 2), out of twelve total. It's generating the containing divs for each post, but the custom_post_meta (the actual video embed, title, description) is not being loaded within those... – dmoz Sep 11 '14 at 21:39
  • I think you need to show the code that is supposed to output the meta that you speak of. – vancoder Sep 11 '14 at 22:20
  • Okay, I added the rest of the loop. It's identical for both pages, and, again, the homepage one shows every video in the correct category, while the documentary one (and corporate.php) does not. – dmoz Sep 11 '14 at 22:53
  • you can get the post id with get_the_ID() function. Can you add the header where the name of the templates is? – Tomás Cot Sep 11 '14 at 23:13
0

For those looking for an answer:

My meta fields id's in functions.php had a variable @prefix applied before the name. I added that prefix on the template and, voile!

Still unsure why my homepage template was working correctly with the wrong meta id's, but an answer nonetheless.

|improve this answer|||||
  • Glad you got there in the end. – vancoder Sep 12 '14 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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