Quick solution to display a menu like list of WordPress Custom Post Type Posts(with Custom Taxonomy) in case of emergency

Well, I was in a hurry, the customer needed to have his site working as soon as possible, and I had to display a menu like list of WordPress Custom Post Types working for three different languages, but I didn’t have time to think of a elegant way to make it work. So I’ve created this little hack, that checks the custom taxonomy for each post and uses a conditional to decide what happens as a quick solution, and I’m sharing with you, to use in a case of emergency🙂
Bem, eu estava com pressa, o cliente precisava ter seu dite funcionando o mais rápido possível, e eu tinha que exibir uma lista tipo menu de Tipos de Posts Customizados WordPress funcionando para três diferentes idiomas, mas eu não tinha tempo para pensar em um jeito elegante de fazer funcionar. Então criei este pequeno hack que verifica a taxonomia customizada para cada post e decide o que acontece usando uma condicional como uma solução rápida, e estou compartilhando com vocês, para usarem em caso de emergência🙂

<ul class="submenu">
   <?
   // here it's the query for my custom post type - Movies 
   $querycp = array( 'post_type'=>'Movies','posts_per_page' => -1 );
   query_posts($querycp);
   while (have_posts()) : the_post();
   // here we check what's the post custom taxonomy, if it is the language we need
   $terms = get_the_terms(get_the_ID(), 'movies_cat');
    foreach ( $terms as $term ) {
        $catref = $term->slug;
    }
   //
     if($catref=="english"):
     ?>
      <li><a href="<?=get_permalink()?>" title=""><?=get_the_title()?></a></li>
     <?
     endif;
   endwhile;
    ?>
</ul>

,

  1. #1 by justin on August 4, 2011 - 5:38 pm

    Nice! Thanks very helpful

    • #2 by Alvaro Neto on August 9, 2011 - 5:33 pm

      thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: