Support

Account

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….