【发布时间】:2020-07-08 12:26:25
【问题描述】:
如何替换高级自定义字段的标准帖子类别链接?
我使用以下代码在每个帖子中显示相关类别
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p>
<strong>Found in:</strong>
<?php
$id = get_the_ID();
$cats = get_the_category($id);
$c = 0; $n = 0;
$c = count($cats);
foreach ( $cats as $cat ):
$n++; ?>
<a href="<?php echo get_category_link($cat->cat_ID); ?>">
<?php echo $cat->name; echo ( $n > 0 && $n < $c ? ', ' : ''); ?>
</a>
<?php endforeach; ?>
</p>
<?php endwhile; ?>
我想将 href 中显示的默认类别 url 替换为我的自定义类别字段,称为循环内每个类别的自定义 url。
【问题讨论】:
标签: wordpress advanced-custom-fields