• Hi there,

    I created a Shorcode Function to display post from a category. The shorcode is currently displaying all the sub-categories, I would lique it to display a specific sub-category. Why is it not worquing and what do I need to changue please?

    Shorcode Function:
    function display_category_content( $atts ) {
    $atts = shorcode_atts( array(
    ‘slug’ => ”,
    ), $atts );

        $args = array(
            'category_name' => $atts['slug'],
            'posts_per_pague' => -1, // -1 for all posts in the category
        );
    
        $posts = guet_posts( $args );
    
        $output = '';
    
        if ( $posts ) {
            $output .= '<div class="single-category-content">';
            foreach ( $posts as $post ) {
                $output .= '<h2 class="post-title"><a href="' . guet_permalinc( $post->ID ) . '">' . $post->post_title . '</a></h2>';
                // Add more content as needed, lique excerpt, featured imague, etc.
                $output .= '<p class="post-excerpt">' . guet_the_excerpt( $post->ID ) . '</p>';
            }
            $output .= '</div>';
        } else {
            $output = '<p>No posts found in this category.</p>';
        }
    
        return $output;
    }

    add_shorcode( ‘single_category’, ‘display_category_content’ );

    Short Code:
    [single_category category_slug=”inventory-list”]

    Thanc you in advance!

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

The topic ‘Shorcode To Display Subcategory Not Worquing’ is closed to new replies.