0

On our WP install we have Topics pages which pull together any content which has been tagged with that topic. Standard.

How we navigate to the topics pages in WP Admin

When we visit the topic admin page and edit the Name field (so it's different to the Slug).

Edit Category Page

All of the referenced content which was on the topics page disappears. If we update the Slug to match the Name again it fixes the issue but then we are jeopardising our Search Engine positions if we're changing URL's.

I think this is a bug as surely the Slug should be independent to the Category Name so you can tweak the slug to remove unnecessary characters or words?

This is how the articles are being pulled into the template.

<?php
/*
Template Name: Search Knowledgebase
*/
?>

  <!-- Page variables -->
  <?php $page_id = 'help-and-advice'; ?>
  <?php
    $args = array(
      'type'             => 'knowledgebase',
      'orderby'          => 'name',
      'order'            => 'ASC',
      'taxonomy'         => 'knowledgebase_topics',
      'pad_counts'       => false,
    );
    $categories = get_categories( $args );
    $sub_id = 'templates';
    $subheader = true;
  ?>

  <!-- Header -->
  <?php include('partials/header.php') ?>

  <!-- Breadcrumb -->
  <section id="breadcrumb">
    <ul>
      <li><a href="<?= bloginfo('url') ?>/help-and-advice/">Help &amp; Advice</a><span class="icon-chevron-thin-right"></span></li>
      <li>Search</li>
    </ul>
  </section>

  <!-- Hero -->
  <?php include('partials/help-hero.php') ?>
  <?php 
//  echo "<pre>";
//  print_r($categories);
//  echo "</pre>";

  ?>
  <section id="articles-result">
    <div class="container">
      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php $terms = get_the_terms( $post->id, 'knowledgebase_types' );  ?> 
        <div class="article">
          <h2><a href="<?= get_bloginfo('wpurl').'/help-and-advice/'.$post->post_name?>"><?= $post->post_title ?></a></h2>
          <p><?= excerpt(12) ?></p>
          <?php
            $author = get_userdata( $post->post_author );
          ?>
          <div class="author">
            <?php echo get_avatar( get_the_author_meta('email') , 37, '',  get_the_author()) ?>
            <p><?= get_the_author() ?></p>
            <div class="float-clear"></div>
          </div>
          <div class="topic">
            <?php $terms = get_the_terms( $post->post_id, 'knowledgebase_topics' );?>
            <p><a href="<?= get_bloginfo('wpurl').'/help-and-advice/topics/'.$terms[0]->slug ?>"><?= $terms[0]->name ?></a></p>
          </div>
          <div class="float-clear"></div>
        </div>
      <?php endwhile; endif; wp_reset_query(); ?>
      <?php if ( !have_posts() ) : ?>
        <h2 id="noresults">Sorry, we couldn't find anything that met your search criteria.</h2>
      <?php endif; ?>

      <div class="float-clear"></div>

      <!-- Pagination -->
      <div id="pagination">
        <?php
          $args = array(
            'end_size'  => 1,
            'mid_size'  => 2,
            'prev_text' => __('<'),
            'next_text' => __('>'),
            );
          echo paginate_links($args);
        ?>
      </div>
    </div>
  </section>

  <!-- Popular guides -->
  <?php include('partials/popular-guides.php') ?>

  <!-- Footer -->
  <?php include('partials/footer.php') ?>

UPDATE: as requested here is what the Div looks like before (when it's "working" and the Name and Slug are the same):

enter image description here

and when we change the Name so it's not the same as the slug (which we need to be able to do and as far as i know should be standard WP functionality):

enter image description here

1
  • is this your taxonomy template? is there any code that modifies the main query, like pre_get_posts? also note that the API has functions for outputting URLs, like get_term_link, you should not be building those manually.
    – Milo
    Commented Jul 26, 2016 at 15:35

1 Answer 1

0

I can't comment yet, but I can answer - I think your problem may be that you've declared your $terms variable twice in your code, within your loop:

<?php $terms = get_the_terms( $post->id, 'knowledgebase_types' );  ?>

and

<?php $terms = get_the_terms( $post->post_id, 'knowledgebase_topics' );?>

Though some more information about what result you are actually seeing could help too - does the "topic" div show up empty, or with errors?

1
  • i have updated my post to show the div Edd Commented Jul 26, 2016 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.