Wednesday, July 20, 2022
HomeWordPress Developmentclasses - Class title for all posts getting assigned to a single...

classes – Class title for all posts getting assigned to a single random publish


This website exhibits an odd conduct the place the class names for posts fetched by get_the_category() returns an empty array. Nevertheless, a single random publish will get the class names of all of the posts(if web page has 20 posts then this random publish shows 20 identical class names). The code used to fetch the class title for the posts:

<?php
    if ( isset( $wp_option[ 'post_type' ] ) && $wp_option[ 'post_type' ] == 'publish' ) {
        $classes = get_the_category();
        
    } else {
        $classes = get_the_terms( $product_post_id, $wp_option[ 'select_post_taxonomy' ] );
        
    }
    $output="";
    if ( ! empty( $classes ) ) {
        foreach ( $classes as $class ) {
            $output .= '<a href="' . esc_url( get_category_link( $class -> term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', WP_TD ), $class -> title ) ) . '" goal="' . $link_target . '">' . esc_html( $class -> title ) . '</a>' . $separator;
        }
        ?>
        <div class="category-list">
            <?php
            
            echo trim( $output, $separator );
            ?>
        </div>
        <?php
    }
?>

The question loop:

whereas ( $question -> have_posts() ) {
            $question -> the_post();

            $product_post_id = get_the_ID();
            $wp_extra_option = get_post_meta( $product_post_id, 'wp_extra_option', true
           <div class="category-wrap">
             //embody the code to show class 
           </div>
);

Each different data akin to publish id, publish title, publish excerpt and so forth are proven if their respective features the_title(), get_the_id() and so forth are known as. Just for the array returned by get_the_category() perform do I get this conduct. Any perception concerning this problem could be helpful.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments