如何在我的主题中显示所有woocommerce类别标题都是自定义字段值。
类似于下面的html示例
<li><a href="#">
<div>
<h2>category title</h5>
<h3>custom field one value</h6>
</div>
<div class="imgpos">custom field two value</div>
</a></li>
我尝试了很多方法,但仍然没有成功
<?php
$post_type = \'product\';
// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( (object) array( \'post_type\' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :
// Gets every "category" (term) in this taxonomy to get the respective posts
$terms = get_terms( $taxonomy );
foreach( $terms as $term ) :
$posts = new WP_Query( "taxonomy=$taxonomy&term=$term->slug&posts_per_page=2" );
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();
?>
<a href="<?php the_permalink(); ?>"><span><?php the_title(); ?></span></a><br><br>
<?php
endwhile; endif;
endforeach;
endforeach;
?>
UPDATE 1下面的代码只给了我类别标题和链接,但无法计算如何获得服装字段值
<?php
$args = array(
\'number\' => $number,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'hide_empty\' => $hide_empty,
\'include\' => $ids
);
$product_categories = get_terms( \'product_cat\', $args );
$count = count($product_categories);
if ( $count > 0 ){
foreach ( $product_categories as $product_category ) {
echo \'<h4><a href="\' . get_term_link( $product_category ) . \'">\' . $product_category->name . \'</a></h4>\';
$args = array(
\'posts_per_page\' => -1,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'slug\',
// \'terms\' => \'white-wines\'
\'terms\' => $product_category->slug
)
),
);
}
}
?>
下面是获取自定义值代码的示例。我想把它放在里面
<?php if( get_field(\'hexagon_thumbnail\') ): ?>
<img src="<?php the_field(\'hexagon_thumbnail\'); ?>" />
<?php endif; ?>