• antoposse

    (@antoposse)


    Hello everyone, I’m using this plugin recently and I created a custom field with a select dropdown and this is the code to put in my template

    <?php print_custom_field('difficolta'); ?>

    I insert it in the loop of home.php, exactly in the article.
    In the first article generated by Worpdress, the custom field is shown, however, in the second article no.

    I ask for your help. Thank u

    http://ww.wp.xz.cn/extend/plugins/custom-content-type-manager/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Can you paste some of the code from your template? Be sure to use the “code” formatting so we can read it.

    Thread Starter antoposse

    (@antoposse)

    This in my home.php

    <?php
    /**
     * The main template file
     */
    ?>
    <?php Starkers_Utilities::get_template_parts( array( 'parts/shared/html-header', 'parts/shared/header' ) ); ?>
    
    <div id="slider"> </div>
    <div id="container">
      <div id="content">
        <?php if ( have_posts() ): ?>
        <ol>
          <?php while ( have_posts() ) : the_post(); ?>
          <li>
            <article class="home">
              <div id="meta">
                <h2><a href="<?php esc_url( the_permalink() ); ?>" title="<?php the_title(); ?>" rel="bookmark">
                  <?php the_title(); ?>
                  </a></h2>
                <time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate>
                  <?php the_date(); ?>
                </time>
                <div class="categoria">
                  <?php
    					$categories = get_the_category();
    					$separator = ' ';
    					$output = '';
    						if($categories){
    						foreach($categories as $category) {
    						$output .= '<span>Categoria:</span> <a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
                                                }
    						echo trim($output, $separator);
                                            }
    				?>
                </div>
    
                <div class="difficolta"> <span>Difficoltà:</span><?php print_custom_field('difficolta'); ?></div>
    
                <?php the_excerpt(); ?>
              </div>
              <div class="image">
                <?php the_post_thumbnail( 'medium' ); ?>
              </div>
            </article>
          </li>
          <?php endwhile; ?>
        </ol>
      </div>
      <?php Starkers_Utilities::get_template_parts( array( 'parts/shared/sidebar' ) ); ?>
    </div>
    </div>
    <?php else: ?>
    <h2>No Post</h2>
    <?php endif; ?>
    <?php Starkers_Utilities::get_template_parts( array( 'parts/shared/footer','parts/shared/html-footer') ); ?>

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    That looks like it should work — WP relies insanely on global variables, however, so it’s tough to know exactly what it’s going. The loop is an Ok idea, but WP’s implementation hurts my brain.

    Thread Starter antoposse

    (@antoposse)

    I do not know what to say!
    So just as it is written should work whenever generates an Article?
    Because, this is the problem. If I have a single article… this code works if the items are more than two code only works in one of the articles just!!

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    The loop is a pain: it’s very hard to debug. I don’t know what to say either other than WordPress is a pain. You can try using the built-in get_post_meta() function instead of the CCTM’s print_custom_field() function and see if that’s any better.

    Thread Starter antoposse

    (@antoposse)

    <?php $meta_values = get_post_meta($post_id, $key, $single); ?>

    the parentheses should put the name of my field right?

    Thread Starter antoposse

    (@antoposse)

    I added this code

    <?php $meta_values = get_post_meta('difficolta'); ?>

    but I have always the same problem. The custom field is printed only once

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Please read the docs: http://codex.ww.wp.xz.cn/Function_Reference/get_post_meta

    You’re using the function incorrectly.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Show the same field multiple times’ is closed to new replies.