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.

I have a wp_query for a custom post type and the custom taxonomy, the idea is top display the term name and below each term the associated posts. I have two languages Dutch & French. Query is working fine for the dutch but in french query is displaying posts for one term and not for others, I have assigned the posts to the terms.

Here is my code:

<div class="list-docs-cat" id="cat-accordion">
  <?php
  $termargs = array(
    'orderby'       => 'name', 
    'order'         => 'ASC',
    'hide_empty'    => false, 
);

 $terms = get_terms("documentation-category", $termargs);
 {
      foreach ( $terms as $term ) {
       echo '<a class="docs-cat-link" href="'.get_term_link($term->slug, 'documentation-category').'">'.$term->name.'</a>';
       ?>
  <?php
       $args = array (
                'post_type'=> 'documentation',
                'showposts'=> -1,
                'documentation-category'=> $term->name
       ); 

      $list_query = new WP_Query($args);  
        echo '<div class="list-docs-post">';
        echo '<ul class="arrow">';
       while ($list_query->have_posts()) : $list_query->the_post();

           echo '<li class="docs-p-title">';
                echo '<a href="#documentation-'. get_the_ID() .'">';
                 the_title();
            echo     ' </a>';
           echo "</li>";

    endwhile;
    echo "</ul>";
    echo "</div>";
        wp_reset_query();
        ?>
  <?php
     }

 }
                ?>
</div>
share|improve this question
    
Your question is about commercial plugin. Most likely your problem is described in WPML docs or it's a WPML bug, not Wordpress's. Have you tried WPML support? –  Max Yudin Mar 2 '13 at 8:05
    
@MaxYudin if you look in the sidebar of this post, you will see plenty of WPML related questions... –  Piet Mar 4 '13 at 9:57
add comment

1 Answer

Recently I needed something very similar as what you describe.

Please find below the working code for the taxonomy.php template. Once added to your theme and you are visiting a single taxonomy term it will output a list of posts (title & excerpt) of the "documentation" custom post type that belong to that particular taxonomy term.

// sample code for taxonomy.php - http://wordpress.stackexchange.com/q/89054/2015
$taxonomy = get_query_var( 'taxonomy' );
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$documentation_args = array(
    'post_type' => 'documentation',
    'tax_query' => array(
        array(
            'taxonomy' => $taxonomy,
            'field' => 'slug',
            'terms' => $term->slug
        )
    ),
    'orderby' => 'menu_order title',
    'order' => 'ASC'
);
$documentation_query = new WP_Query($documentation_args);

echo '<div class="documentation-content">';

if ($documentation_query->have_posts()) { 

    while ($documentation_query->have_posts()) { $documentation_query->the_post(); $count++;

        $title_before = '<h2 class="title">';
        $title_after = '</h2>';

        $title_before = $title_before . '<a href="' . get_permalink( get_the_ID() ) . '" rel="bookmark" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">';
        $title_after = '</a>' . $title_after;

?>

    <div <?php post_class(); ?>>
        <?php the_title( $title_before, $title_after ); ?>
        <div class="entry tax_archive">
            <?php the_excerpt(); ?>
        </div><!-- /.entry -->
    </div><!-- /.post -->

<?php
    } // End WHILE Loop

} else {

    echo '<p class="no-content">' . sprintf(__('There is no content available yet for <strong>%s</strong>', 'textdomain'), $term->name ) . '</p>';    

} // End IF Statement

echo '</div>'; // End .documentation-content
share|improve this answer
    
Hello Piet, Your code does not work for me, its just displaying me "There is no content available yet for" . I am using this code in the sidebar, I have created a custom widget to display the term names and below listed post titles for the same. –  Himanshu Jain Mar 5 '13 at 6:56
    
Hi, Thanks anyways, I found the solution. I was using $term->name which should be $term->slug –  Himanshu Jain Mar 5 '13 at 7:15
    
glad you got it to work, can be a pain to get it right :) –  Piet Mar 5 '13 at 10:46
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.