• Resolved Anonymous User 13441596

    (@anonymized-13441596)


    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)
  • Hi Jwssnr,

    Read this tutorial. Hope it will helpful for you.

    Thread Starter Anonymous User 13441596

    (@anonymized-13441596)

    I already did and it did not. But thanks. I’ve been searching for quiet a while.

    Thread Starter Anonymous User 13441596

    (@anonymized-13441596)

    Okay. Now I know it is possible, but way to hard for me. I switch over from categories to custom fields.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Order posts by category slug’ is closed to new replies.