如果自定义帖子的标题与其他帖子的标题匹配,则显示代码 时间:2012-12-13 作者:RogerNobrega 我有两个自定义帖子,一个叫做“评论”,另一个叫做“指南”。如果两篇文章的标题匹配,我想显示一个来自帖子评论的自定义字段。类似这样的:(我不擅长代码,这是我用来解释我认为应该如何的方式)<? php if (\'$post_title\' \'guides\' == \'$post_title\' \'reviews\') { echo (\'custom_field\' \'reviews\'); else return __(no details); } ?> 1 个回复 SO网友:brasofilo 如果您引用的是默认的自定义字段,则没有明确提及。如果是,则以下解决方案不适用。但是,比默认设置好得多的是创建一个自定义元框,在其中显示自定义字段。法典中有一个例子Function_Reference/add_meta_box.这些也很有用:add meta box - custom field : which to choose?How to add option box in "Edit Post" plugin API?检查代码中的注释以及MB中打印的消息add_action( \'add_meta_boxes\', \'add_meta_box_wpse_75963\' ); function add_meta_box_wpse_75963() { // This prevents the code from going further if not in the correct post type global $post; if( \'reviews\' != $post->post_type ) return; // Check if the other post type has a post with the same title // If it doesn\'t, bail out $other_page = get_page_by_title( $post->post_title, OBJECT, \'guides\' ); if( !$other_page ) return; // We are in the correct post_type (reviews) // and there is another post in "guides" with the same title add_meta_box( \'wpse_42440_sectionid\', __( \'Custom Field\' ), \'display_meta_box_wpse_75963\', \'reviews\' ); } function display_meta_box_wpse_75963() { echo "Insert custom field procedures here."; echo "Also create the appropriate <code>add_action( \'save_post\', \'callback\');</code>"; } 结束 文章导航