cinelink
cinelink

Reputation: 1

Strage Problem in Wordpress Custom Post Type?

I have a blog, and I have added one custom post type 'Movies'. and I have link it to my single-movies.php. and added this code:

    <div id="container">
<?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 Problem is, I'm clicking on any movie, its showing me only same movie, which i have added last on custom field Movies (i.e Avatar Movie, if I click on stargate movie, Its showing me 'Avatar' Movie link. and same others)

Please help me and change this code, if I did anything wrong here.

Upvotes: 0

Views: 68

Answers (2)

ovi_mihai
ovi_mihai

Reputation: 91

when you are in single-movies.php it means you are already on the right path like /movies/avatar

so doing a simple loop

<?php while (have_posts()) : the_post(); ?>
    <?php the_title(); //.... ?>
<?php endwhile; ?>

gives you all details of the avatar movie, you don't need to query, because the query is already made by the time you arrive to a SINGLE Movie page!

/movies/avatar means:

post type = movies

post name = avatar

also if you have pretty links, $_GET['movie'] it normally contains nothing. it is prefered to use the $wp->query_vars['post_name'] to get the movie name

try just putting the loop and see what you get, if not dump the $_GET and $wp to see where you have the movie name.

Upvotes: 1

bboy
bboy

Reputation: 1408

you have a problem with the loop. I would say to use a foreach...look at this example, maybe it will help you. it is exactly the same as you want 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; ?>

Upvotes: 0

Related Questions