Wordpress custom taxonomy paged getting 404 not found
I have a custom taxonomy called "dcategory" so I have created a template file called "taxonomy-dcategory.php" to determine how its shown. Here is the code for this template:
<?php
global $paged, $wp_query;
get_header();
?>
<div id="leftcontent">
<?php if(is_user_logged_in()) : ?>
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
if($term->parent == 0) : ?>
<h1>Specialist Directory</h1>
<h2><?php echo $term->name; ?></h2>
<ul>
开发者_开发百科 <?php
$subtermcats = get_terms('dcategory', 'hide_empty=0&parent='.$term->term_id.'&orderby=name');
foreach($subtermcats as $key => $data) {
$termlink = get_term_link($data, 'dcategory');
echo "<li><a href=\"".$termlink."\">".$data->name."</a></li>";
}
?>
</ul>
<?php else: ?>
<h1>Specialist Directory</h1>
<?php
$topterm = get_term_by( 'id', $term->parent, get_query_var( 'taxonomy' ) );
?>
<h2><?php echo $topterm->name; ?> > <?php echo $term->name; ?></h2>
<?php
// Include Search - Search results returned in $_SESSION['lpoc_search_data'];
include("functions/directorysearch.php");
if(count($_SESSION['lpoc_search_data']) > 0) {
$temp = $wp_query;
$wp_query = null;
$args = array(
'post_type' => 'listings',
'post__in' => $_SESSION['lpoc_search_data'],
'showposts' => 10,
'paged' => $paged,
'orderby' => 'post__in'
);
$wp_query = new WP_Query($args);
} else {
query_posts("cat=9999999"); // Make a fake query that will be empty to flush out the content from the page we are on
}
?>
<?php if (have_posts()) : ?>
<div class="pageination clearfix">
<div class="smallleftcontent">
<select name="sortby" class="dropdownreplace">
<option value="date-desc">Order by latest added</option>
<option value="date-asc">Order by oldest added</option>
<option value="price-asc">Order by price ascending</option>
<option value="price-desc">Order by price descending</option>
</select>
</div>
<div class="smallrightcontent">
<?php wp_pagenavi(); ?>
</div>
</div>
<?php while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<div class="pageination clearfix">
<div class="smallleftcontent">
<select name="sortby" class="dropdownreplace">
<option value="date-desc">Order by latest added</option>
<option value="date-asc">Order by oldest added</option>
<option value="price-asc">Order by price ascending</option>
<option value="price-desc">Order by price descending</option>
</select>
</div>
<div class="smallrightcontent">
<?php wp_pagenavi(); ?>
</div>
</div>
<?php else: ?>
<?php endif; ?>
<?php endif; ?>
<?php else: // USER NOT LOGGED IN ?>
<?php include("functions/pleaseregister.php"); ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Here is what is happening:
Check if user is logged in. If not show register info. If user is on a parent dcategory then the chosen dcategory children is shown. If user is on child dcategory then run my own custom brewed database query that gets IDs of posts in an order based on distance from user to post. Results are returned in a session array and passed as a custom query to $wp_query. The query works and the page shows the first ten posts along with the pagination generated by wp_pagenavi (all correct).
But when navigating to page 2 I am returned a page not found:
http://www.example.com/dcategory/antiques/ to http://www.example.com/dcategory/antiques/page/2/
Any ideas why this is happening?
Thanks
Scott
Resave the permalink settings...
I have kind of solved this myself.
My custom query was returning more results than what wordpress was returning for the chosen category. So when I was going on page two there wasnt enough results so getting a page not found.
So instead of creating a new query I setout to filter the existing results with this instead:
<?php
// Include Search - Search results returned in $_SESSION['lpoc_search_data'];
include("functions/directorysearch.php");
query_posts(
array_merge(
array( 'post__in' => $_SESSION['lpoc_search_data'], 'orderby' => 'post__in' ),
$wp_query->query
)
);
?>
When you register a new custom taxonomy you need to save the permalinks settings again, be sure to resave it.
精彩评论