Last active
October 3, 2018 19:11
-
-
Save faaezahmd/60ff18c522d39470aa4a273e45052f68 to your computer and use it in GitHub Desktop.
Get WP ACF-Plugin Field value from child category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Get Advanced Custom Field value from child category | |
*/ | |
$cats = get_categories('child_of='.get_query_var('cat')); | |
foreach ($cats as $cat) : | |
$args = array( | |
'posts_per_page' => 3, // max number of post per category | |
'category__in' => array($cat->term_id) | |
); | |
$my_query = new WP_Query($args); | |
if ($my_query->have_posts()) : | |
echo '<h3>'.$cat->name.'</h3>'; | |
// 'background_image' Custom Field | |
the_field('background_image', 'category_' . $cat->term_id); | |
echo $cat->description; | |
while ($my_query->have_posts()) : $my_query->the_post(); ?> | |
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a> <br /> | |
<?php endwhile; ?> | |
<?php else : | |
echo 'No Posts for '.$cat->name; | |
endif; | |
endforeach; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment