Home › Forums › Add-ons › Flexible Content Field › List of slugs from custom post taxonomy for loop › Reply To: List of slugs from custom post taxonomy for loop
I’ve been trying to do something similar. I needed to pull list of category Names and slugs and use them to populate a News feed. I’m sure this is probably not the best way to do it but it worked for me.
//vars
$terms = get_sub_field('filter_news_feed');
//set variables for the category slug and category name
$output = "";
$nameOutput = "";
//Loop throuh each item in the array and assign the slug and name values to their variables
foreach( $terms as $term ):
$output.= $term->slug . ', ';
$nameOutput.= $term->name . ', ';
endforeach;
//trim the last , and space ' ' off of the list
$trimOutput = rtrim($output,', ');
//trim the last , and space ' ' off of the list
$trimNameOutput = rtrim($nameOutput,', ');
and then to load it into the array:
$args = array(
'post_type' => 'post',
'post_parent' => 0,
'posts_per_page' => 4,
'order' => 'DSC',
);
//adding 'category_name' => 'slug, slug, slug, etc'; to args array
$args['category_name'] = $trimOutput;
Hope that helps….
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.