• First of all, I hope this is the place where I can start a topic. If it’s not, sorry for disturbing.

    Actually my problem is so simple: I am using Zylyz recipe theme. I set the home page to a custom post type (recipes), but as you might guess, when I press the “Older Entries” button it gives “not found” error, because it tries to get ordinary blog posts, not “recipes” (you know, if I had enough blog post it wouldn’t give error, but would show posts, not recipes). So, how can I get rid of this problem?

    Thank you very much in advance.

    Here’s the home page’s codes:

    <div id="content">
    
    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('post_type=recipes'.'&paged='.$paged);
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>	
    
    <div class="post clearfix" id="post-<?php the_ID(); ?>">
    <?php
    	if ( has_post_thumbnail() ) { ?>
    	<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&h=200&w=200&zc=1" alt="<?php the_title(); ?> Recipe"/></a>
    		<?php } else { ?>
    	<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('template_directory'); ?>/images/dummy.jpg" alt="" /></a>
    <?php } ?>
    <div class="cover">
    	<div class="title">
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?> Recipe"><?php the_title(); ?></a></h2>
    	</div>
    	<div class="recipemeta">
    		<span class="cooktime"> <strong>ready in</strong> <?php $cooktime=get_post_meta($post->ID, 'wtf_cooktime', true); echo $cooktime; ?> mins </span> <span class="serve"> <strong>Serving:</strong> <?php $serving=get_post_meta($post->ID, 'wtf_serving', true); echo $serving; ?> people</span>
    	</div>
    	<div class="entry" align="justify">
    		<?php wpe_excerpt('wpe_excerptlength_recipe', ''); ?>
    		<div class="clear"></div>
    	</div>
    </div>
    </div>
    
    <?php endwhile; ?>
    <div class="clear"></div>
    
    <?php getpagenavi(); ?>
    
    <?php $wp_query = null; $wp_query = $temp;?>
    
    </div>
Viewing 6 replies - 1 through 6 (of 6 total)
  • You have a few things incorrectly setup for using WP_Query(), even then, pagination doesn’t work as you are calling to an undefined variable called $paged. While this is what the main query uses, your query needs to define it when passed to WP_Query().

    Try out the code I have here and see if that helps. I also readjusted some things that will help solidify and secure your code you listed. Check out the second link for a diff of what I changed.
    https://gist.github.com/colegeissinger/8628947
    https://gist.github.com/colegeissinger/8628947/revisions

    Thread Starter isasari

    (@isasari)

    Thank you very much Cole, but I’ve already solved it by myself. I appreciate your help.

    Hey isasari could you pass me your code, I’m having the same problem

    Could you please pass me your code?

    Thread Starter isasari

    (@isasari)

    Hey psahmad. Here is my codes: This one is for functions.php

    if ( !is_admin() ) add_filter( 'pre_get_posts', 'my_get_postss' );
    
    function my_get_postss( $query ) {
    
    	if ( is_home() && $query->is_main_query() ){
    
    		$query->set( 'post_type', array( 'recipes' ) );
    		$query->set('posts_per_page', 6);                       
    
    	}
    	return $query;
    }

    And this one is for home page:

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('post_type=recipes'.'&paged='.$paged);
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

    Isasari

    I really need your help with one.

    When you are saying it is for “home page” – what do you mean by that?

    I have the same problem and I have been spending two days now with not solution ??

    Plz help me out – it would mean the world to me.

    Thanks in advance

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom post type pagination problem’ is closed to new replies.