Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using a template, which uses Custom Post Type 'movies'. When I try to change the page I got 404 Not Found :(

This is my index.php

<div id="content">
<?php
$temp = $wp_query;
$page = get_query_var('page');
$page = (!empty($page) ? $page : 1);
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=movies'.'&posts_per_page=6&paged=$page');
?>
<?php while (have_posts()) : the_post(); ?> 

<div class="box " id="post-<?php the_ID(); ?>">

<div class="boxentry">
<div class="btitle">
    <h2 align="center"><a href="<?php the_permalink() ?>" rel="bookmark" title="Ver <?php the_title(); ?>"><?php echo get_post_meta($post->ID, 'wtf_ryear', true); ?></a></h2>
</div>
<!--div class="clear"></div-->
</div>

<div class="boxim">
<?php
if ( has_post_thumbnail() ) { ?>
    <a href="<?php the_permalink() ?>"><img class="boximg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&amp;h=270&amp;w=180&amp;zc=1" alt=""/></a>
<?php } else { ?>
    <a href="<?php the_permalink() ?>"><img class="boximg" src="<?php bloginfo('template_directory'); ?>/images/dummy.png" alt="" /></a>
<?php } ?>

</div>

</div>

<?php if(++$counter % 4 == 0) : ?>
<div class="clear"></div>
<?php endif; ?>

<?php endwhile; ?>

<div class="clear"></div>
<?php getpagenavi(); ?>
<?php $wp_query = null; $wp_query = $temp;?>
</div>

And this is my Post Type:

function post_type_movies() {
register_post_type(
'movies', 
array( 'public' => true,
        'publicly_queryable' => true,
        'has_archive' => true, 
        'hierarchical' => false,
        'menu_icon' => get_stylesheet_directory_uri() . '/images/movie.png',
        'labels'=>array(
            'name' => _x('Movies', 'post type general name'),
            'singular_name' => _x('Movie', 'post type singular name'),
            'add_new' => _x('Add New', 'Movies'),
            'add_new_item' => __('Add New Movie'),
            'edit_item' => __('Edit Movie'),
            'new_item' => __('New Movie'),
            'view_item' => __('View Movie'),
            'search_items' => __('Search Movies'),
            'not_found' =>  __('No Movies found'),
            'not_found_in_trash' => __('No Movie found in Trash'), 
            'parent_item_colon' => ''
            ),                           
        'show_ui' => true,
        'menu_position'=>5,
        'query_var' => true,
        'rewrite' => TRUE,
        'rewrite' => array( 'slug' => 'pelicula', 'with_front' => FALSE,),
        'register_meta_box_cb' => 'mytheme_add_box',
        'supports' => array(
            'title',
            'thumbnail',
            'comments',
            'editor'
            )
        ) 
);
} 
add_action('init', 'post_type_movies');

Check it out at http://ddlpremium.com/peliculeros

Thanks in advance.

share|improve this question
2  
Please show us your research efforts and explain why all the other solutions didn’t work in your case. ;) –  toscho Jul 31 '12 at 12:17
add comment

2 Answers

Couple of small corrections:

$wp_query is a global variable so you need to declear it as a global and i believe the query var is paged not page. so,

change

$temp = $wp_query;
$page = get_query_var('page');

to

global $wp_query;
$temp = $wp_query;
$page = get_query_var('paged');

Check if that works. Also I prefer to use Singular for CPT names. movie instead of movies.

share|improve this answer
add comment

Have you tried using double quotes around the query string with the variable?

Change:

$wp_query->query('post_type=movies'.'&posts_per_page=6&paged=$page');

to

$wp_query->query('post_type=movies'."&posts_per_page=6&paged=$page");

If that doesn't fix it, try dumping the query after the above code var_dump( $wp_query ) it may show what is causing the issue.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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