Php 显示Wordpress自定义字段$value

Php 显示Wordpress自定义字段$value,php,wordpress,custom-fields,Php,Wordpress,Custom Fields,我试图在循环之外,在一个幻灯片窗口中的一组8个帖子特色图片缩略图下,使用自定义字段显示另一个缩短的帖子标题。我可以使用以下代码片段在这些缩略图下显示相应帖子的标题: <?php $titletext = get_the_title(); echo( $arr[$i]['titletext'] ); ?> 我可以在循环中显示自定义字段: <?php $key="short_title"; echo get_post_meta($post->ID, $key, true

我试图在循环之外,在一个幻灯片窗口中的一组8个帖子特色图片缩略图下,使用自定义字段显示另一个缩短的帖子标题。我可以使用以下代码片段在这些缩略图下显示相应帖子的标题:

<?php $titletext = get_the_title(); echo( $arr[$i]['titletext'] ); ?>

我可以在循环中显示自定义字段:

<?php $key="short_title"; echo get_post_meta($post->ID, $key, true); ?>

但我在循环之外尝试过的两种方法的任何组合都不会返回任何结果,或者在每个缩略图下返回“Array”。这个解决方案看起来很明显,但我一直在逃避。有人能告诉我如何正确地做到这一点吗

添加更多代码以进行澄清:

    <?php if (have_posts()) : while (have_posts()) : the_post();
     global $post; ?>
        <?php if ( $responsive ) { ?>
            <li class="slide">
        <?php } else { ?>
            <div class="slide">
        <?php } ?>
                <?php
                $width = $responsive ? 560 : 558;
                $height = 340;
                $small_width = 110;
                $small_height = 63;
                $titletext = get_the_title();

                $thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Featured');

                $arr[$i]['thumbnail'] = get_thumbnail($small_width,$small_height,'',$titletext,$titletext,false,'Small');
                $arr[$i]['titletext'] = $titletext;

                $thumb = $thumbnail["thumb"];
                print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
                <div class="featured-top-shadow"></div>
                <div class="featured-bottom-shadow"></div>  
                <div class="featured-description scrollcustom">
                <div class="feat_desc">
                    <h2 class="featured-title"><a href="<?php the_permalink(); ?>"><?php the_title()  ?></a></h2>

                        <p>                 <?php $key="short_title"; echo $shorttitle; ?> <?php the_content(); ?></p>
                    </div>

                </div> <!-- end .description -->

        <?php if ( $responsive ) { ?>
            </li> <!-- end .slide -->
        <?php } else { ?>
            </div> <!-- end .slide -->
        <?php } ?>
        <?php $i++; endwhile; endif; wp_reset_query(); ?>
<?php if ( $responsive ) { ?>
    </ul> <!-- end .slides -->
<?php } else { ?>
    </div> <!-- end #slides -->
<?php } ?>
</div> <!-- end #featured -->

<div id="controllers" class="clearfix">
    <ul>
        <?php for ($i = 0; $i < $featured_num; $i++) { ?>
            <li>
                <div class="controller " >
                    <a href="#"<?php if ( $i == 0 ) echo ' class="active"'; ?>>
                    <?php $titletext ?>
                        <?php print_thumbnail( $arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height ); ?>
                    <span class="overlay"></span><br>
                                    <?php echo( $arr[$i]['titletext'] ); ?>  
                    </a>
                </div>  
            </li>   
        <?php } ?>


    如果您在循环之外,则需要
    全局$post
    粘贴整个循环代码。它在循环之外,因此我不确定这是否有帮助。添加以澄清问题。@user1279351粘贴与您的问题相关的中断代码,并请指出其中断的位置。@dalbaed这是答案
    global$post
    是保存查询的全局变量。如果你在循环中,你不需要它。