Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter wscheer

    (@wscheer)

    Actually, I found a fix.
    Instead of using “cat_name” you can use “category_nicename”. The nice name is the category slug. IE: Condos & Beach Houses -> condos-beach-houses
    There seems to be no issue with length using the slug.

    I have highlighted the change below with =================

    <?php //get the current category and put into $category var
    $category = get_the_category();
    echo "<h2 class='headline'>".$category[0]->cat_name."</h2>";
    //
    //
    // ==========================================
    $cat = $category[0]->category_nicename;
    // ==========================================
    //
    //
    ?>
    
    <?php $recent = new WP_Query(); ?>
    
    // for testing what the 'get_the_category()' output was
    <?php echo "cat: ".$cat; ?>
    
    // this was working for some categories but not others
    <?php $recent->query('category_name='.$cat.'&showposts=-1'); ?>
    
    <?php while($recent->have_posts()) : $recent->the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
    <?php endwhile; ?>

    Hope that helps someone

Viewing 1 replies (of 1 total)