Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In educational courses database, institute is used as custom taxonomy. How can I display description of "institute" taxonomy in all related posts as one institute will have at least 50 posts (courses)...

share|improve this question
add comment

2 Answers

Assumptions:

  • institute is the taxonomy
  • course is the term
  • only one course is assigned per post
  • you want to display the course description?

If so, the simplest way would be to use get_the_terms(). If your taxonomy is institute, you can do something like the following:

<?php
// globalize $post
global $post;
// Get the course for the current post
$post_courses = get_the_terms( $post->ID, 'institute' );
// Assuming only one course, get the first object of the array
$post_course = $post_courses[0];
// Get the course description
$course_description = $post_course->description;
// Output the course description
echo $course_description
?>

If my assumptions are incorrect, then let me know in the comments, and I'll update the answer.

EDIT

Other assumption is all right but I want to show "institute description". Only one course is assigned per post but each institute contains several courses. Institute is taxonomy and name of institutes are used as categories.

I'm still not entirely sure that I'm following you. Are you saying that institute and course are hierarchical taxonomies? If so, then my original assumptions are incorrect. Can you more clearly describe your schema?

EDIT 2

In this case, I want to show description of university of Auckland. While this university is also used in many other posts. In my case, each course is a post.

Okay, now we're getting somewhere! It seems that course is a Custom Post Type, and that institute is a Custom Taxonomy for that CPT. If this is correct, then my above code should work for displaying the term description for a given post.

share|improve this answer
    
Thanks Bennett. Other assumption is all right but I want to show "institute description". Only one course is assigned per post but each institute contains several courses. Institute is taxonomy and name of institutes are used as categories. –  Ahmad Oct 31 '11 at 7:04
    
I am very sorry sir, I am not a professional developer so might be using wrong terms to explain. Please have a look at this.. wikivisas.com/courses/bachelor-of-science-in-bioinfrmatics In this case, I want to show description of university of Auckland. While this university is also used in many other posts. In my case, each course is a post. –  Ahmad Nov 1 '11 at 6:57
    
Should I use it as $post_courses as I have no t created (course) custom post type. i am using the default post type for this purpose and only have created taxonomies. –  Ahmad Nov 1 '11 at 19:07
    
Post or Custom Post Type shouldn't matter, since you're querying the taxonomy, anyway. –  Chip Bennett Nov 1 '11 at 19:08
add comment

Here is the code that I used recently to display each Term within the Custom Taxonomy (called Service Types), with the description, and then under it displays all of the custom post types (Services) underneath it.

I added an if statement so that if a Service_type does not have a description it does not create the div for it (so there is not a big blank space). You can modify it to show your particular custom taxonomy. This will at least get you started. I did some other pages as well that were to show specific terms within the taxonomy, so if you need more info write out a description.

<?php

//get all service_types (custom taxonomy) then display all posts in each term

$taxonomy = 'service_types';



$term_args=array(

    'orderby' => 'menu_order',

    'order' => 'DESC'

);

$terms = get_terms($taxonomy,$term_args);



if ($terms) {

   foreach( $terms as $term ) {



    $args=array(

      'post_type' => 'services',

      'service_types' =>  $term->name ,

      'post_status' => 'publish',

      'posts_per_page' => 50,

      'caller_get_posts'=> 1

      );

    $my_query = null;

    $my_query = new WP_Query($args); 

    if( $my_query->have_posts() ) {  ?>





    <div class="services">  <!--begin this type of service -->  

       <div class="description">

        <h4><?php echo $term->name;?></h4>



        <?php

            $termDiscription = $term->description;

                if($termDiscription != '') : ?>

                    <p><?php echo $termDiscription; ?></p>

                <?php endif; ?>

        </div>  <!--.description -->



        <?php

      while ($my_query->have_posts()) : $my_query->the_post(); ?>



<!--begin this service -->

                  <div class="cpt service"> 

                  <h5><?php the_title(); ?></h5><!--title -->

                    <!--thumbnail -->

                    <span class="sthumb">   

                        <a href="<?php the_permalink() ?>" title="<?php echo $term->name;?>"><?php the_post_thumbnail(); ?></a>

                    </span>

                    <!--#thumb -->



                    <?php the_excerpt(); ?>



                  </div><!--#cpt -->



       <?php endwhile; ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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