A little issue with looping out posts with categories

Hi,

I have a FAQ on a website, that outputs categories of a custom taxonomy, and it works well… until i noticed something. If the category NAME has non-english letters (swedish site so has å,ä,ö) and if i use spaces in the name the posts of the category won’t be output on the page, just the category name.

When I create a category i choose a category name, and a permalink, example: “Försäkring” gets the permalink “forsakring”, and I guess I have to get the posts by this one instead of the actual name. However I don’t know how to adjust my code for it.

Here it is:

<?php $categories = get_categories( array('taxonomy' => 'faq-category') ); ?>

<?php foreach ( $categories as $category ) :

	$cat_name = $category->name; ?>

	<div class="row">
		<div class="large-12 columns">
			<h2><?php echo $cat_name ?></h2>
		</div>
		<div class="large-12 columns faq-columns"> 

			<?php query_posts( array( 'post_type' => 'questions', 'faq-category' => $cat_name ) );

			if (have_posts()) : while (have_posts()) : the_post(); ?>

				.......

			<?php endwhile; endif; wp_reset_query(); ?>

		</div>
	</div>

<?php endforeach; ?>

Sounds like you want to use the category slug instead of the category name -

$category->slug

Look up get_categories in the WordPress codex. It will give you a list of all the parameters you can use with it, along with a few examples.

http://codex.wordpress.org/Function_Reference/get_categories

1 Like

Thanks man, you are a hero. Worked fine.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.