在Wordpress中隐藏某个自定义字段

时间:2014-01-19 19:08:07

标签: php wordpress custom-fields

我想隐藏名为external_URL的WordPress中的某个自定义文件。即使它有一些价值,我也不希望它显示出来。

我正在使用<?php the_meta(); ?>来显示自定义字段。

你能帮忙吗? 谢谢。

编辑:这是single.php代码

<?php

get_header(); // Loads the header.php template
if (have_posts()) : while (have_posts()) : the_post(); ?>

<div id="single-post-content" class="clearfix">

    <div id="single-post" class="clearfix">

        <header id="post-header">
            <h1><?php the_title(); ?></h1>
            <ul class="meta clearfix">
                <li><strong>Posted on:</strong> <?php echo get_the_date(); ?></li>
                <li><strong>By:</strong> <?php the_author_posts_link(); ?></li>   
                <?php if(comments_open()) { ?><li class="comment-scroll"><strong>With:</strong> <?php comments_popup_link(__('0 Comments', 'wpex'), __('1 Comment', 'wpex'), __('% Comments', 'wpex'), 'comments-link' ); ?></li><?php } ?>
            </ul>
        </header><!-- /post-header -->

        <!-- Entry Content Start -->
        <article <?php post_class('entry clearfix fitvids'); ?>>
            <div class="inner-post">
                <div class="meta-block">
                    <div class="post-image">
                        <img src="<?php echo get_post_meta($post->ID, "external_featured", true); ?>" />
                    </div>
                    <div class="custom-fields">
                        <?php the_meta(); ?>
                        <div class="meta-ad">
                            <img src="http://lorempixel.com/160/600" alt="">
                        </div>
                    </div>
                </div>
                <div class="the-content">
                   <?php the_content(); // This is your main post content output  ?>
                </div>

            </div><!-- /inner-post -->
        </article><!-- /entry -->
        <!-- Entry Content End -->
        <?php wp_link_pages(); // Paginate pages when <!- next --> is used ?>

        <div id="categories">
            <p class="filed-under">Filed Under:</p>
            <?php
                $categories = get_the_category();
                $separator = ' ';
                $output = '';
                if($categories){
                    foreach($categories as $category) {
                        $output .= '<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="tags-main">
            <p class="tags">Tags:</p>
            <?php the_tags('<div id="post-tags" class="clearfix">','','</div>'); ?>
        </div>

    </div><!-- entries-wrap -->

    <?php get_sidebar(); ?>

        <div class="clearfix">
            <?php comments_template(); ?>
            <?php 
            // Get random posts
            $wpex_related_posts = get_posts('numberposts=6&orderby=rand&exclude='. $post->ID);
            if($wpex_related_posts) { ?>
            <section id="related-posts" class="clearfix">
                <h2><span><?php _e('Random Posts','wpex'); ?></span></h2>
                <div id="entries-wrap" class="clearfix"> 
                    <?php
                    //start loop
                    $wpex_count=0;
                    global $post;
                    foreach($wpex_related_posts as $post) : setup_postdata($post);
                    $wpex_count++;
                        get_template_part( 'content', '' ); // get entry
                    if( $wpex_count == 6 ) { echo '<div class="clear"></div>'; $wpex_count=0; } endforeach; wp_reset_postdata(); ?>
                </div><!-- entries-wrap -->
            </section><!-- /related-posts -->
            <?php } ?>
        </div><!-- /clearfix -->



</div><!--/container -->

<?php
//end post loop
endwhile; endif;
//get template footer
get_footer(); ?>

1 个答案:

答案 0 :(得分:1)

尝试在functions.php中添加此代码: -

add_filter('the_meta_key', 'filter_my_meta', 10, 3);
function filter_my_meta($val, $key, $value) {
    if( $key === 'external_URL' ) {
        return '';
    }
    return $val;
}