I've got a blog, and that i have added one custom publish type 'Movies'. and that i have link it to my single-movies.php. and added this code:
<?php $args = array( 'post_type' => 'movies', 'posts_per_page' => 1, 'name' => $_GET['movie'] ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h1> <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"> <?php the_title(); ?> </a> </h1> <div class="entry-content"> <?php the_content(); ?> </div> </div> <?php endwhile; ?> </div> <?php include(TEMPLATEPATH . '/sidebar_single.php'); ?> <?php get_footer(); ?>
But Issue is, I am hitting any movie, its showing me only same movie, which i've added last on custom area Movies (i.e Avatar Movie, basically click stargate movie, Its showing me 'Avatar' Movie link. and same others)
Help me and alter this code, basically did anything wrong here.
you don't have to query, just loop
<?php while (have_posts()) : the_post(); ?>
you have trouble with the loop. I'd say to utilize a foreach...see this example, maybe it can help you. it's exactly like you need to achieve.
<?php $cat_id = $category->cat_ID; // YOU CAN CHANGE THIS OR REMOVE global $post; $args = array( 'category' => $cat_id, 'numberposts' => -1 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : start_wp(); ?> <li class="subcat-post-title"> <span class="trigger"> <a class="ficha" href="<?php the_permalink() ?>"> <?php echo the_title(); ?> </a> <?php endforeach; ?>