Help with custom post types for client website!

Hi,
I have searched high and low on google for an answer to this question and haven’t found anything that works :frowning:

Basically i am developing a client website where I have used the Custom Post Type UI plugin to create a post type called “events”. I then have a custom page template called events.php which runs a loop that displays all posts of the type “events”. My loop is displayed below:


        <?php query_posts('post_type=events&post_status=publish&posts_per_page=5' ); ?>
        <?php if (have_posts ()) : ?>
        <?php while(have_posts()) : the_post(); ?>
					
          <div class="event">
          <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
          <p><?php the_field('event_date') . the_field('event_time'); ?></p>
            <?php the_excerpt(); ?>
            <a style="color: black; text-decoration: underline;" href="<?php the_permalink(); ?>">Read More...</a>
          </div><!-- end event -->
			
        <?php endwhile; ?>	

          <div id="postsnav"><?php posts_nav_link(); ?></div><!-- end postsnav -->

        <?php else : ?>
			
          <p>Nothing Here!</p>
				
        <?php endif; ?>
        <?php wp_reset_query(); ?>

It partly works, as when I navigate to the events page, the 5 most recent events are displayed. However when i click “next page”, I simply get a page saying “Nothing here” rather than the next events posts :confused:

Does anyone know whats wrong here? It seems to be navigating to /events/page/2 and the title of the page is “page not found”. Pulling my hair out here lol :confused:

no one? :confused:

Well if I am not wrong with the little wordpress knowledge that I have you wont be able to achieve pagination through regular query_posts query easily. The workaround would be to use WP_Query. Look for the documentation and they have option which states posts per page and paged which I guess will solve your navigation issue. See if it helps or get back.

OK i have tried loads of things… been looking all over google for an answer… here is my modified loop

<?php
  $type = 'events';
  $args=array(
    'post_type' => $type,
    'post_status' => 'publish',
    'paged' => $paged,
    'posts_per_page' => 4,
    'caller_get_posts'=> 1
  );
  $temp = $wp_query;
  $wp_query = null;
  $wp_query = new WP_Query($args);
?>

<?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
  <div class="event">
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <p><?php the_field('event_date'); ?><!--<?php the_field('event_date') . the_field('event_time'); ?>--></p>
        <?php the_excerpt(); ?>
        <a style="color: black; text-decoration: underline;" href="<?php the_permalink(); ?>">Read More...</a>
  </div><!-- end event -->
<?php endwhile; ?>
  <nav>
    <?php previous_posts_link('&laquo; Newer') ?>
    <?php next_posts_link('Older &raquo;') ?>
  </nav>
<?php else : ?>
  <p>Nothing Here!</p>
<?php endif; ?>

However, still the same problem - the posts display on the page as they should, but when you click the next link it displays “nothing here” instead of the later posts :confused:

OK - ive just realised. When the permalinks are set to “default”, it works fine… but when set to %postname% it doesn’t work… any ideas?? :confused:

Well I checked the above query with wp_query and it works fine with permalinks or without permalinks. What is the exact issue you are facing? One thing you can try is for your custom post type have query vars = true and then check