jcadima
2/1/2019 - 11:00 PM

Get Generated Post Class


https://hotexamples.com/examples/-/-/get_post_class/php-get_post_class-function-examples.html

<?php
$day_cats = get_terms( ['taxonomy' => 'day_category'] ) ;


$taxonomy = 'day_category';
$args = array( 'parent' => 0  ); // get only parent terms
$terms = get_terms( $taxonomy, $args );

// Get All Menu Items
$resourcequery = new WP_Query( [
    'post_type' => 'menu_day',
    'posts_per_page' => -1,

] );

// Use  post class to generate menu categories
if ( $resourcequery->have_posts() ) {
    while ( $resourcequery->have_posts() ) {
        $resourcequery->the_post(); ?>
        <div id="post-<?php the_ID(); ?>" class="<?php echo implode(' ', get_post_class())  ; ?> box">
            <?php  echo '<p>' . get_the_title() . '</p>'; ?>
        </div>
        <?php
    }

} else {}
wp_reset_postdata();
?>

get_post_class() is an array, is not just an echoing alternative to post_class() 


Will Generate something like:
post-194 menu_day type-menu_day status-publish hentry day_category-breakfast day_category-new box

Use post_class() for regular output