Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3871616
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:50:27+00:00 2026-05-19T21:50:27+00:00

I have a custom taxonomy called dcategory so I have created a template file

  • 0

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; ?> &gt; <?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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T21:50:28+00:00Added an answer on May 19, 2026 at 9:50 pm

    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
                )
            );
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wordpress taxonomy called product. I know the template file for my
I have the following code to build a custom taxonomy for my portfolio: add_action(
I have a custom taxonomy setup called albums, and a new album can be
I have setup a custom taxonomy called video_categories and have set it to two
I have Googled this but cannot find an answer. I have created a custom
I have successfully created a custom taxonomy in WordPress, and I created a page
I have a Custom Taxonomy called groups as part of my species Custom Post
So. I created a custom WordPress taxonomy. And I have multiple posts that use
I have a custom post type FAQ and custom taxonomy Category. I want to
I have custom UITableViewCell . It contains UITextLabel . When I press this cell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.