Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

awdriggs on "Getting List of custom taxonomy with links"

$
0
0

I have created a custom post type with a custom taxonomy. I want to have a list of all the categories in the custom taxonomy that links to the most recent post in that category.

I hacked together this from what I found in other forum posts.

<?php

		$post_type = 'samiamido_work';
		$tax = 'stationary';
		$tax_terms = get_terms($tax);
		if ($tax_terms) {
		  foreach ($tax_terms  as $tax_term) {
			$args=array(
			  'post_type' => $post_type,
			  "$tax" => $tax_term->slug,
			  'post_status' => 'publish',
			  'posts_per_page' => 1,
			  'caller_get_posts'=> 1
			);

			$my_query = null;
			$my_query = new WP_Query($args);
			if( $my_query->have_posts() ) {
			  echo 'List of '.$post_type . ' where the taxonomy '. $tax . '  is '. $tax_term->name;
			  while ($my_query->have_posts()) : $my_query->the_post(); ?>
				<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
				<?php
			  endwhile;
			}
			wp_reset_query();
		  }
		}
		?>

But there are two problems that I can't figure out how to resolve...
1) It only returns one category type, that has to be defined "stationary" in this case. I envision have at least 4 categories, so that would be a lot of repetition and I'm looking for something dynamic.

2) It outputs the same message and link twice.

If anyone could give advice or point me in the right direction I would really appreciate it. I'm fairly new to theme development.


Viewing all articles
Browse latest Browse all 8245

Trending Articles