• topherx

    (@topherx)


    I need some help. I feel like I’ve already solved this years ago but its totally stumping me on this new site.

    I’m trying to make an attachment template where the attachment image is displayed with its Caption and description fields. Then the capture line is used to call a page with the same name. Here is the code that isn’t working:

    <?php
    $title = get_the_title();
    $title = strtolower($title);
    $page = 'pagename='.$title;
    ?>
    	<?php while ( have_posts() ) : the_post(); ?>
                  <?php get_template_part( 'content', 'attachment' ); ?>
    	<?php endwhile; // end of the loop. ?>
    <?php
    // the query for the page with the same name as the caption
    $new_query = new WP_Query( $page ); ?>
    
    <?php if ( $new_query->have_posts() ) : ?>
    	<?php get_template_part( 'content', 'page' ); ?>
    	<?php wp_reset_postdata(); ?>
    <?php else : ?>
    	<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>

    Where am I going wrong? Thanks

  • The topic ‘Passing Variables between loops’ is closed to new replies.