0
我在我的网站上使用高级自定义字段。 我创建了一个自定义字段“关系”,以显示在我的所有产品类别页面上(我正在使用woocommerce,这就是为什么我使用product_cat_
而不是category
在我的php中)。显示产品类别页面上的acf自定义字段的关系
当使用一个基本的文本字段,我abble显示我的分类页面上的文本,使用此代码:尝试使用这一类页面内的关系功能时
<?php
$term_id = get_queried_object()->term_id;
$post_id = 'product_cat_'.$term_id;
?>
<div><?php the_field('text', $post_id); ?></div>
<?php ?>
,但现在,我没有从我选择的帖子得到正确的标题和永久链接,并且我找不到如何修改我的代码...
这是我的代码,我的自定义字段名为mise_en_avant_produit
,它返回一个帖子对象。
<?php
$term_id = get_queried_object()->term_id;
$post_id = 'product_cat_'.$term_id;
$posts = get_field('mise_en_avant_produit', $post_id);
if($posts):
?>
<?php foreach($posts as $post): ?>
<?php setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php ?>
我已经使用了这种代码,以显示例如从另一个页面关系领域,但在这里我无法找到解决办法,
这里是我得到的时候print_r
Array ([0] => WP_Post Object ([ID] => 42 [post_author] => 1 [post_date] => 2014-09-16 17:22:07 [post_date_gmt] => 2014-09-16 16:22:07 [post_content] => . [post_title] => Green tea [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => green-tea [to_ping] => [pinged] => [post_modified] => 2014-09-25 08:36:41 [post_modified_gmt] => 2014-09-25 07:36:41 [post_content_filtered] =>
[post_parent] => 0 [guid] => http://localhost:8888/bemygift/?product=green-tea [menu_order] => 0 [post_type] => product [post_mime_type] => [comment_count] => 0 [filter] => raw))
有人可以帮我吗?
非常感谢,
你能否澄清:1 - 你说你没有得到正确的标题和固定链接。你的意思是你得到不正确的标题或没有标题? 2.你可以'print_r($ posts)',这样我们就可以看到它是在检索 – Dre 2014-09-29 19:18:57
@Dre,谢谢你的回复。我得到一个标题,但不是我在我的自定义字段中选择的一个... – mmdwc 2014-09-29 19:36:06
这里是我在print_r – mmdwc 2014-09-29 19:37:16