In my theme on home page i want to show call category name two custom file value. i tried so long but not success yet.
bellow will be my html code
<li class="wow fadeInDown" data-wow-duration="1.5s" data-wow-delay="0.3s"><a href="#">
<div class="textpos">
<h5>Category Name</h5>
<h6>custom field one</h6>
</div>
<div class="imgpos">custom field two</div>
</a></li>
for custom filed i am use AFC
so custom field one value can get bellow way
<?php the_field('custom_title'); ?>
custom filed two value can get bellow way
<?php
$image = get_field('image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
bellow code i got in internet which can display categories name but i couldn’t figure out how to apply my html and AFC value there.
<?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
)
),
);
}
}
?>
UPDATE 1
bellow is another code which almost work not what i wanted. i want title and now coming all category title and all products name too
<?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;
?>