0

Hello again Wordpress Stack,

I'm having trouble getting my custom post to display under a custom category.

The post in question is this:

register_post_type('feature_article',
        array(
            'labels' => array(/* left out for clarity */),
            'query_var' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'supports' => array('thumbnail', 'title', 'excerpt'),
            'public' => true,
            'has_archive' => true,
            'menu_position' => 5,
            'taxonomies' => array('twin')
            )
        );

and the registered taxonomy is here:

    add_action( 'init', 'twin_post_taxonomy', 0 );

function twin_post_taxonomy() {
    $labels = array(/* for clarity */ );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'twin' ),
        );

    register_taxonomy( 'twin', array( 'feature_article','post'), $args );
}

I'm trying to call the post in question here (I called the category "double portrait"):

 <?php $args = array( 'post_type' => 'feature_article', 'posts_per_page' => 1, 'article_genre' => $str, 'orderby' => 'modified');  
   $loop = new WP_Query($args); ?>
 <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

 <?php if ( in_category('double portrait') ) { 
           echo the_title(); 
  } else { 
           echo the_excerpt(); 
  } ?>

    <?php endwhile;  wp_reset_postdata(); ?>

Sorry for the long messy code :/

Edit: I am getting the output excerpt instead of title.

2
  • Do you mean the slug is twin and its name is 'double portrait'? Where does 'article_genre' fit in?
    – vancoder
    Commented Jul 31, 2013 at 21:33
  • @vancoder The category name is double portrait. Article genre is another custom taxonomy I'm using, that seems to be working fine though.
    – UzumakiDev
    Commented Jul 31, 2013 at 21:39

1 Answer 1

1

in_category is only for the built-in category taxonomy. If you want to check a custom taxonomy term, use has_term:

if ( has_term( 'double portrait', 'twin' ) ) {
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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