doujing5726 2014-01-19 19:08 采纳率: 0%
浏览 94
已采纳

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

I want to hide a certain custom filed in WordPress named external_URL. I don't want it display even if there is some value in it.

I am using the <?php the_meta(); ?> to display custom fields.

Can you guys help? Thank you.

Edit: Here is the single.php code

<?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条回答 默认 最新

  • dtpoius74857 2014-01-19 19:39
    关注

    Try adding this code in your 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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况