【问题标题】:How can I create Custom Fields in a Custom Post Type?如何在自定义帖子类型中创建自定义字段?
【发布时间】:2015-01-11 15:12:55
【问题描述】:

我有一个自定义帖子类型页面,这是我使用的代码:

<?php
 get_header();
 get_sidebar();
 the_meta();
?>

<ul class="event">
  <?php $args = array( 'post_type' => 'event-netzwerk', 'posts_per_page' => 30, 'orderby' => 'rand' );
  $loop = new WP_Query( $args );
  while ( $loop->have_posts() ) : $loop->the_post();
    echo '<li>';
    the_title('<h3>', '</h3>');
    the_content();
    echo '</li>';
  endwhile; ?>
</ul> 


<?php

 get_footer();
?>

有人知道我如何在那里添加 AFC 吗?

【问题讨论】:

    标签: php wordpress post types ctp


    【解决方案1】:

    要在您的主题中显示 ACF,请使用 the_field()

    <h1><?php the_field('custom_title'); ?></h1>
    

    【讨论】:

    • 那不可能,我不想用插件。我想自己编码。但是网上找不到好的教程
    • 如果你想添加一个元框,而不是一个高级自定义字段,那么你的问题就跑题了。 “ACF”代表高级自定义字段......这是一个插件。 @Dinesh 有一个正确的答案。
    • 我已经在我的主题中添加了自定义帖子类型,现在我想添加(高级)自定义字段。如果 Advanced(...) 是一个插件,那我很抱歉。我不想安装插件我需要一些代码将其编码到我的模板中
    • 您正在尝试添加元框、值和键。不是字段。 codex.wordpress.org/Function_Reference/add_meta_box
    【解决方案2】:

    你可以使用_field函数。

    the_field("your_custom_field");
    

    https://wordpress.org/plugins/advanced-custom-fields/screenshots/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 2020-06-06
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多