How to display a Wiki name by its category name or category id

I would like to display the names of wikis on a page that have a specific category name or category id it is assigned to in the "Wiki Category" window when editing a Wiki. For example, if I have the category "Root" with slug "root" and Category ID of 23, I would like to display on a page all Wikis that have the category "Root" or ID of 23. Thanks.

  • Becky

    This is the code that I have in the file archive-incsub_wiki.php in my theme folder:

    <?php
    //Place this php file in theme folder
    $args = array(
    	'post_type' => 'incsub_wiki',
    	'post_parent' => 0,
    	'numberposts' => -1,
    	'tax_query' => array(
        array(
          'taxonomy' => 'incsub_wiki_category',
          'field' => 'slug',
          'terms' => 'root', // Where slug of Root is "Root".
          'operator' => 'IN',
        ),
      ),
    );
    
    $the_query = new WP_Query( $args );
    
    get_header();
    
    ?>
        <div id="primary" class="site-content">
            <div id="content" role="main">
            <h1 style="text-decoration: underline;">Your Wikis</h1> <!-- Display this text as title -->
            </br> <!-- Add a line between the title and Wiki titles -->
    
    <!-- Begin the Loop -->
    <?php if ( $the_query->have_posts() ) {
         ?><a href="<?php the_permalink(); ?>"><?php the_title( '<h3>', '</h3>' ); ?></a><?php ;
    } else {
         echo wpautop( 'No Wikis were found, please add some' ); // no posts found
    }
    ?>
    <!-- End of the Loop -->
    </div><!-- #content -->
    </div><!-- #primary -->
    
    <?php wp_reset_postdata() ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Problem is that I have one Wiki named Medical that is tagged with category "Root" with slug of "root" and that title is not showing, instead another Wiki is showing that is not tagged with that category. Here is the link to my Wiki Archive page to see what is being output by this code: WIKI ARCHIVE PAGE. Please take a look and see what needs to be changed please. I have the WPMUDev Dashboard installed and Support is currently active. Thanks!

  • Becky

    OK, I fixed it. I was missing some code. Code that does work is here:

    <?php
    //Place this php file in theme folder
    $args = array(
    	'post_type' => 'incsub_wiki',
    	'numberposts' => -1,
    	'tax_query' => array(
        array(
          'taxonomy' => 'incsub_wiki_category',
          'field' => 'slug',
          'terms' => 'root', // Where slug of Root is "Root".
          'include_children' => TRUE,
          'operator' => 'IN',
        ),
      ),
    );
    
    $the_query = new WP_Query( $args );
    
    get_header();
    
    ?>
        <div id="primary" class="site-content">
            <div id="content" role="main">
            <h1 style="text-decoration: underline;">Your Wikis</h1> <!-- Display this text as title -->
            </br> <!-- Add a line between the title and Wiki titles -->
    
    <!-- Begin the Loop -->
    <?php if ( $the_query->have_posts() ) {
         while ( $the_query->have_posts() ) {
         $the_query->the_post();
         ?><a href="<?php the_permalink(); ?>"><?php the_title( '<h3>', '</h3>' ); ?></a><?php ;
         }
    } else {
         echo wpautop( 'No Wikis were found, please add some' ); // no posts found
    }
    ?>
    <!-- End of the Loop -->
    </div><!-- #content -->
    </div><!-- #primary -->
    
    <?php wp_reset_postdata() ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Anyone who needs this, just add a Category of "Root" with a slug of "root" and tag all Root Wikis with the "Root" category that you want to show on your Wiki archive page.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.