145 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Located in Australia
+3 more
ThemeChills says

Hi everyone,

So I’ve been trying to create pagination for my custom post type which is on my one page theme. Here is the theme http://wp.themechills.com/eternity/. After numerous hours of Google research, etc, I have come to no solution.

Within the theme I generate custom post types for the Photos section. The problem is I only want the 8 posts to show and then paginate while still on the front page – essentially an ajax call + pagination.

I created a test version here http://wp.themechills.com/sandbox/ just to test without all the clutter.

As you can see, the pagination links to a 404.

Here is my code block for reference. I would really appreciate it if someone can lend me their brain…thoughts?


<?php
  $type = 'photo';
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $args=array(
    'post_type' => $type,
    'post_status' => 'publish',
    'paged' => $paged,
    'posts_per_page' => 8,
    'caller_get_posts'=> 1
  );
  $temp = $wp_query;  // assign original query to temp variable for later use
  $wp_query = null;
  $wp_query = new WP_Query();
  $wp_query->query($args);
?>
<?php

if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="entry">
<h2 class="title"><?php the_title(); ?></h2>

</div>
<?php endwhile; ?>
<div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>

<?php else : ?>
<h2>Not Found</h2>
<p>Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>

1286 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
Smartik says

Go to “Permalink Settings” and click “Save Changes” button. Alternatively you can use flush_rewrite_rules after theme/plugin activation.

145 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Located in Australia
+3 more
ThemeChills says

Go to “Permalink Settings” and click “Save Changes” button.

What do you mean?

136 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Joined an Envato Football competition
+3 more
Konnessa says


Go to “Permalink Settings” and click “Save Changes” button.
What do you mean?

In your admin dashboard, under settings. It is so that wordpress can re-generate the rewrite rules for your new custom post type and allow for the new url types.

1286 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
Smartik says


Go to “Permalink Settings” and click “Save Changes” button.
What do you mean?
In admin dashboard: https://www.dropbox.com/s/su0hcj16jmqfnwg/scr-00081-002%20%281%29.png
145 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Located in Australia
+3 more
ThemeChills says

Thanks guys, I know where saving the permalinks structure is and these have been saved, though this does not resolve my issue.

3711 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says

First of all (but shouldn’t affect things in a 404 way), your $paged variable is wrong. This is how it should look:

$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : ( get_query_var( 'page' ) ? get_query_var( 'page' ) : 1 );
DistinctiveThemes
DistinctiveThemes Recent Posts Threads Started
257 posts
  • Sells items exclusively on Envato Market
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 1 year
  • Contributed a blog post
+3 more
DistinctiveThemes says

First of all (but shouldn’t affect things in a 404 way), your $paged variable is wrong. This is how it should look:
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : ( get_query_var( 'page' ) ? get_query_var( 'page' ) : 1 );

You have just solved a problem iv been having all morning :) – Thank you!

145 posts
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Located in Australia
+3 more
ThemeChills says

Issue still remains. Might need to consider alternatives…

1286 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
Smartik says

Your code has several problems. Here is the corrected version: http://pastebin.com/T55a8gMX

Some notes:

  • caller_get_posts – is deprecated and replaced by ignore_sticky_posts
  • You should never alter the $wp_query variable, use your own var instead. I’ve replaced it for you with $photo_query.
  • This $wp_query->query($args); is useless. The args should be added directly to WP_Query class. new WP_Query( $args );

Further check.

  • Are you sure the ‘photo’ post type exists? Check it with this: var_dump( get_post_types( '', 'names' ); )
  • Is your post type: public, has archive and is publicly queryable? When registering a new post type, these are some of the required parameters:
$post_type = 'photo'

// Set up the arguments
$args = array(
    // ...
    'public'             => true, 
    'has_archive'        => true,
    'publicly_queryable' => true, 
    'query_var'          => true, 
    'rewrite'            => array(
        'slug' => $post_type, // or something else
    ),
    // ...
);

// Register post type
register_post_type( $post_type, $args );

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by