Order posts by category slug
-
Hi there
I’m trying to order my posts by their category slug. But i will not work this way. Everything else seems to be okay. Why?$args = array( 'post_type' => 'p', 'posts_per_page' => 20, 'orderby' => 'category_name', 'order' => 'ASC', ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $kat = get_the_category(); $cat = $kat[0]->cat_name; // $cat = $kat[0]->slug; echo '<tr '; post_class(); echo '><td class="inst"><a href="' . esc_url( get_permalink() ) . '">'; echo $cat; '</a></td>'; echo '<td class="vorn"><a href="' . esc_url( get_permalink() ) . '">'; the_field('vorname'); echo '</a></td>'; echo '<td class="name"><a href="' . esc_url( get_permalink() ) . '">'; the_field('name'); echo '</a></td>'; echo '<td class="jahr"><a href="' . esc_url( get_permalink() ) . '">'; the_field('jahrgang'); echo '</a></td>'; echo '<td class="wohn"><a href="' . esc_url( get_permalink() ) . '">'; the_field('wohnort'); echo '</a></td>'; echo '<td class="site">'; if( get_field('website') ): echo '<a href="'; the_field('website'); echo '">www</a>'; endif; echo '</td>'; echo '<td class="doss">'; if( get_field('dossier') ): echo '<a href="'; the_field('dossier'); echo '">pdf</a>'; endif; echo '</td></tr>'; endwhile;
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Order posts by category slug’ is closed to new replies.