I am a loss here since I have looked at dozens of tutorials and posts all over the internet on how to get the slug for a taxonomy and nothing I try seems to work. The taxonomy shows up fine when I want to edit the post and everything seems to be working fine, however I cannot seem for the life of me to get Wordpress to give me the slugs I want. I am really frustrated and irritated on how complicated the process of saying "for the array of posts you already have, include the taxonomy for each one". sigh
In reality, all I want is to get the custom taxonomy slug that has been selected for each post. I have a portfolio page that I want to make interactive with jquery and I am trying to use the taxonomy slug as the anchors for the jquery script. All I need from Wordpress is to see the post it's already giving me all of it's information and to include the taxonomy it has been already linked to. Then echo that slug into the class of the LI tag.
Here is the code:
<ul>
<?php
$post = 'project'; // custom post type
$i=1;
query_posts("post_type=$post&showposts=-1&order=asc");
$post_count = wp_count_posts();
while(have_posts()) : the_post();
$myExcerpt = get_the_excerpt();
$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", $myExcerpt);
$terms = get_the_terms( $post->id, 'project-type' ); // get an array of all the terms as objects.
$terms_slugs = array();
foreach( $terms as $term ) {
$terms_slugs[] = $term->slug; // save the slugs in an array
}
?>
<li class="project <?php echo $terms_slugs[$i]; ?>">
<a href="<?php the_permalink(); ?>" id="project_<?php echo $id; ?>" class="project_frame">
<?php the_post_thumbnail('full', array('class' => 'project_img')); ?>
<p style="display: none;"><span class="larger"><?php the_title(); ?></span><br /><span class="smaller"><?php echo $myExcerpt; ?></span></p>
</a>
</li>
<?php
$i++;
endwhile;
wp_reset_query();
?>
</ul>
Hopefully someone can help me with this.
UPDATE:
Figured it out. Here is the corrected code.
<ul>
<?php
$post = 'project'; // custom post type
$i=0;
$counter = 0;
query_posts("post_type=$post&showposts=-1&order=asc");
$post_count = wp_count_posts();
while(have_posts()) : the_post();
$myExcerpt = get_the_excerpt();
$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", $myExcerpt);
$slugs = get_terms('project-type');
foreach($slugs as $slug) {
$slug_array[$i] = $slug->slug;
$i++;
}
?>
<li class="project <?php echo $slug_array[$counter]; ?>">
<a href="<?php the_permalink(); ?>" id="project_<?php echo $id; ?>" class="project_frame">
<?php the_post_thumbnail('full', array('class' => 'project_img')); ?>
<p style="display: none;"><span class="larger"><?php the_title(); echo $i;?></span><br /><span class="smaller"><?php echo $myExcerpt; ?></span></p>
</a>
</li>
<?php
$counter++;
endwhile;
wp_reset_query();
?>
</ul>