WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Posts, Custom Fields and Categories (4 posts)

  1. Zen Gonzaga
    Member
    Posted 2 years ago #

    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 :D
    Thanks, i'll wait for this.

  2. NateJacobs
    Member
    Posted 2 years ago #

    You can use the function in_category( category #). Then use an if statement to show the custom field or not.

  3. Zen Gonzaga
    Member
    Posted 2 years ago #

    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? :)

  4. NateJacobs
    Member
    Posted 2 years ago #

    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;
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic