Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

404 on Custom Post Type Taxonomy page WordPress

I have a custom post type called 'education-library' with a custom taxonomy called 'education-library-category'.

Here's the code in my functions file:

// REGISTER CUSTOM POST TYPE FOR EDUCATION LIBRARY
function education_library_post_type() {
register_post_type('education-library',array(
'labels' => array(
'name' => 'Education Library',
'singular_name' => 'Article',
'menu_name' => 'Education Library',
'add_new_item' => __('Add New Article'),
'edit' => __('Edit'),
'edit_item' => __('Edit Article'),
'new_item' => __('New Article'),
'view' => __('View Article'),
'view_item' => __('View Article'),
'search_items' => __('Search Articles'),
'not_found' => __('No Articles found'),
'not_found_in_trash' => __('No Articles found in Trash'),
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'supports' => array('title','editor','thumbnail', 'custom-fields'),
'menu_position' => 25,
'rewrite' => array(
'slug' => 'education-library',
'with_front' => false
),
'capability_type' => 'post',
'hierarchical' => false,
'query_var' => true,
'has_archive' => 'post',
));
}
add_action('init', 'education_library_post_type', 0);

// CREATE TAXONOMY CAPABILITY FOR EDUCATION LIBRARY
function create_education_library_taxonomies() {
register_taxonomy('education-library-category', 'education-library', array(
'hierarchical' => true,
'label' => 'Library Categories',
'query_var' => true,
'public' => true,
'rewrite' => array(
'slug' => 'education-library-category',
'with_front' => false
),
)
);
}
add_action('init', 'create_education_library_taxonomies', 0);


And here's the code for my template file:

<section id="content" class="posts group floatleft">

<?php global $wp_query; ?>
<?php $args = array_merge( $wp_query->query, array( 'posts_per_page' => '1' ) ); ?>
<?php query_posts($args); ?>
<?php if (have_posts()) : ?>

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Video Library Filter')) : ?>
<?php endif; ?>

<h2><?php single_cat_title(); ?></h2>

<?php while (have_posts()) : the_post(); ?>

<article class="posts library-posts group">

<?php if ( has_post_thumbnail() ) : ?>
<div class="post-thumb group">
<?php the_post_thumbnail('large'); ?>
</div><!-- thumb -->
<?php else : ?>
<div class="post-thumb group">
<img src="<?php bloginfo('template_url') ?>/images/no-image-195x130.jpg" alt="no-image-195x130" width="195" height="130" />
</div><!-- thumb -->
<? endif; ?>

<h3 class="post-hd">
<a class="more-link" title="Link to <?php the_title(); ?>" href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>

<div class="meta">
<span class="post-author">
written by <a title="View all posts by <?php the_author_meta('display_name'); ?>" href="<?php the_author(); ?>"><?php the_author_meta('first_name'); ?></a>
</span>
<span class="meta-sep">|</span>
<span class="post-date"><?php the_time('F jS, Y') ?></span>
</div><!-- meta -->


<div class="entry group">
<?php the_excerpt(); ?>
<a class="more-link" title="Link to <?php the_title(); ?>" href="<?php the_permalink(); ?>">
read full article &rsaquo;
</a>
</div><!-- entry -->

</article><!-- post-ID -->

<?php endwhile; ?>

<nav class="posts-nav">
<div class="prev-posts btn"><?php next_posts_link('Older Entries') ?></div>
<div class="next-posts btn"><?php previous_posts_link('Newer Newer') ?></div>
</nav><!-- posts-nav -->

<?php else : ?>

<article id="not-found" class="group">

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Class Schedule Filter')) : ?>
<?php endif; ?>

<h2>Nothing Found</h2>
<p>There are currently no posts assigned to this category.</p>

</article><!-- not-found -->

<?php endif; ?>

</section><!-- content -->


The trouble I'm having is with the next_posts_link. When I click it I get the 404 page as opposed to the previous post.

Here's a link to the page: http://baseline.snapsize.com/education-library-category/video-library


Thanks for the help.

Answers (5)

2011-07-12

Chuck Wilson answers:

Do you have more than one post yet? I've had experiences before where I was showing 8 posts per page, and the default in settings was set to 10, when trying to go to the next page it 404ed because there wasn't 10 more posts, since you only are showing one post at a time I wonder if this could be an issue.

You could also try this plugin which I've used in the past to fix similar issues. http://wordpress.org/extend/plugins/custom-post-type-category-pagination-fix/

Another (possibly less desirable) solution is to set your default number of posts to show to 1.
In WP Admin Settings/Reading/Blog pages show at most


Denis Leblanc comments:

No luck. Installed the plugin, revisited the permalink settings page and still get the 404 page.

I'd like to avoid extra plugins unless I really need them.

Thanks for trying.

d.


Chuck Wilson comments:

Denis, I've got one more trick to try.

replace,

<?php next_posts_link('Older Entries') ?>
<?php previous_posts_link('Newer Newer') ?>


with

<?php previous_posts_link('Older Entries') ?>
<?php next_posts_link('Newer Newer', $loop->max_num_pages) ?>


and

<?php global $wp_query; ?>
<?php $args = array_merge( $wp_query->query, array( 'posts_per_page' => '1' ) ); ?>
<?php query_posts($args); ?>


with

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($query_string .'&posts_per_page=1&paged=' . $paged);?>


If that doesn't work I'm out of ideas, good luck.


Denis Leblanc comments:

No luck with that either. Thanks for the help.

d.

2011-07-12

Maor Barazany answers:

You may want to check the [[LINK href="http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/"]]nextprevious-post-link-plus[[/LINK]] plugin that can help you achieve full support for cpt's and single navigation.

That solution has been helpful also on another [[LINK href="http://wpquestions.com/question/show/id/2542"]]question here[[/LINK]]

You may also try to re-save your permalink structure.


Denis Leblanc comments:

Maor,

I'd really like to stay away from using any more plugins on this website, it's already a beast to begin with. I can't see this being a big issue, I'm just tired of staring at this bit.

Thanks.

d.


Maor Barazany comments:

[[LINK href="http://designrjc.com/fix-previous_posts_link-and-next_posts_link-for-custom-post-types/"]]This post[[/LINK]] might help you too.


Denis Leblanc comments:

Maor,

That didn't help either. Basically the same solution as Chuck's above and neither worked.

Have you guys looked at my function creating the post type and taxonomy? Perhaps I missed something there.

d.


Maor Barazany comments:

A.
In your register_post_type function, try to change-

'has_archive' => 'post',
to
'has_archive' => true,

It thinks that your CPT's archive page is the posts's archive, it may be there.
After you do this, re-save your permalink structure again.

B.
What is the file name of your template file you use?


Maor Barazany comments:

If it is not working, try to change for the test the name of your custom taxonomy to something else, it might be that the prefix of names the same, it might cause errors some times.

Also, in your register_taxonomy function, change the query_var parameter to be a string and not true -


'query_var' => 'education-library-category',


After these changes of course re-save your permalinks.


Denis Leblanc comments:

This is driving me nuts. Can't get anything to work. I will rename my custom taxonomy in the morning and see what I get.

Thanks for your help.


d.

2011-07-12

Erez S answers:

This question is the same as yours:
http://wpquestions.com/question/show/id/2184

Try the solutions there


Denis Leblanc comments:

There was no solution there. It got handled privately and the answer never got shared.

By the sounds of it, custom post types and custom taxonomies aren't advanced enough yet to be able to handle modifying the query.


Erez S comments:

So contact the expert/asker and ask him what was the solution.

2011-07-14

Alex Sancho answers:

could you post your header, footer and full taxonomy template?

2011-07-14

Lucas Wynne answers:

This WILL work, I'm 100% sure... you might need somebody else to add to this answer for you as my time is limited, but you can always split the money how you see fit...

Use this instead of your current code, replace "NUMBER" with the appropriate numbers:

<?php
query_posts('cat=NUMBER&posts_per_page=NUMBER&paged='.$paged);
if (have_posts()) :
?>

<?php while (have_posts()) : the_post(); ?>

<?php endwhile: ?>
<?php endif; ?>