Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 显示从帖子到类别模板的ACF_Wordpress_Advanced Custom Fields - Fatal编程技术网

Wordpress 显示从帖子到类别模板的ACF

Wordpress 显示从帖子到类别模板的ACF,wordpress,advanced-custom-fields,Wordpress,Advanced Custom Fields,我在帖子中创建了一个自定义字段(文本字段),我想在类别模板中显示该字段的值。我是ACF的新手,任何帮助都将不胜感激 提前谢谢你好吧,如果你想循环浏览所有内容,可以这样做。在后端的ACF部分将“field_name”更改为您的字段名称 <?php $cat = get_the_category(); global $post; $args = array( 'posts_per_page' => -1, 'offset'=> 1, 'category' => $cat, '

我在帖子中创建了一个自定义字段(文本字段),我想在类别模板中显示该字段的值。我是ACF的新手,任何帮助都将不胜感激


提前谢谢你

好吧,如果你想循环浏览所有内容,可以这样做。在后端的ACF部分将“field_name”更改为您的字段名称

<?php
$cat = get_the_category();
global $post;
$args = array( 'posts_per_page' => -1, 'offset'=> 1, 'category' => $cat, 'post_type' => 'post', );

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    <li>
     // Assuming you want the link/title to the post
     <a href="<?php the_permalink(); ?>">
      <?php the_title(); ?>

      // Display the custom field value
      <?php echo get_field('field_name'); ?>
     </a>
    </li>
<?php endforeach;
wp_reset_postdata();?>

  • //假设你想要文章的链接/标题

  • 请参见
    从特定帖子获取值
    我想在类别模板中向字段显示属于特定类别的所有帖子的值。例如,我希望属于“优惠”类别的所有产品都有零售价和网络价