• Resolved Zen Gonzaga

    (@zen-gonzaga)


    Hey guys i have custom posts name ‘story’.
    I have displayed the categories.. working just fine.
    I need to show a custom post field.
    I want to show ‘chapter’ field when ‘NOVEL’ category is included in categories.

    Have any idea?
    Please ??
    Thanks, i’ll wait for this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can use the function in_category( category #). Then use an if statement to show the custom field or not.

    Thread Starter Zen Gonzaga

    (@zen-gonzaga)

    Oh i’m sorry i don’t understand what you mean.
    Here is how i displayed my Categories:

    <?php
    $terms = wp_get_object_terms( $post->ID, 'category' );
      foreach( $terms as $term )
      $term_names[] = $term->name;
      echo implode( ', ', $term_names );
    ?>

    I want to show the field Chapter: $chapter if the Category Novel is displayed in Categories.
    How am i gonna do it? ??

    You can use it like this in your single page template.

    <?php
    // used in the loop
    // is this post in the category novel?
    if ( in_category( 'novel', $post->ID ) )
    {
            // if so, get the chapter meta and display it
    	$chapter = get_post_meta($post->ID, 'chapter', true);
    	echo "Chapter: ".$chapter;
    }
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Posts, Custom Fields and Categories’ is closed to new replies.