如何回显/显示特定自定义字段名称的自定义字段值?

时间:2014-07-31 20:12:49

标签: php wordpress

我试过这段代码:

        <?php 
            query_posts(array(
            'meta_key' => 'custom_cat',
            'meta_value' => 'creative',
            'post_type' => 'page'
        ));
            echo '<ul id="creative_services" class="clearfix row">';
            if ( have_posts() ) while ( have_posts() ) : the_post();
                    echo '<li class="col-md-3">';
                    echo '<a class="popover-dismiss" data-toggle="popover" title="';
                    echo $post->post_title;
                    echo '" data-placement="bottom" data-content="';
                    echo $post->post_content;
                    echo '"><i class="';
                    get_post_meta( get_the_ID(), 'fa_icon' );
                    echo '"></i></a>';
                    echo '<h3>';
                    the_title();
                    echo '</h3>';
             endwhile; 
            echo '</ul>';
            wp_reset_query(); ?>

将自定义字段值显示为类名,但不显示该值。请帮我找到问题或解决方案,将自定义字段值显示为类名。我很难调试这些代码,因为我不是程序员,我是设计师,仍然在探索wordpress。

1 个答案:

答案 0 :(得分:0)

尝试在echo之前添加get_post_meta( get_the_ID(), 'fa_icon' ); 所以它会是:

<?php 
        query_posts(array(
        'meta_key' => 'custom_cat',
        'meta_value' => 'creative',
        'post_type' => 'page'
    ));
        echo '<ul id="creative_services" class="clearfix row">';
        if ( have_posts() ) while ( have_posts() ) : the_post();
                echo '<li class="col-md-3">';
                echo '<a class="popover-dismiss" data-toggle="popover" title="';
                echo $post->post_title;
                echo '" data-placement="bottom" data-content="';
                echo $post->post_content;
                echo '"><i class="';
                echo get_post_meta( get_the_ID(), 'fa_icon' );
                echo '"></i></a>';
                echo '<h3>';
                the_title();
                echo '</h3>';
         endwhile; 
        echo '</ul>';
        wp_reset_query(); ?>