Get post type of wp grid builder cards

343 Views Asked by At

I'm trying to add the post type as a class in the cards (article element).

I was messing with this:

function set_class_postype( $atts, $card ) {
 
    $grid = wpgb_get_grid_settings(1);
$post_type = get_post_type( $post->ID );
    
$atts['class'] = $post_type;
 
        return $atts;
 
}
add_filter( 'wp_grid_builder/card/attributes', 'set_class_postype', 10, 2 );

But that, obviously, only outputs the post type where the grid builder shortcode is. Which is a page. So that is what outputs https://i.stack.imgur.com/IZmE4.png

1

There are 1 best solutions below

0
On

Found the solution!

I simply added:

    $object = wpgb_get_object();
$post_type = $object->post_type;

So, the final snippet is:

function set_class_postype( $atts, $card ) {

    $grid = wpgb_get_grid_settings(1);
$object = wpgb_get_object();
$post_type = $object->post_type;
    
$atts['class'] = $post_type;

        return $atts;

}
add_filter( 'wp_grid_builder/card/attributes', 'set_class_postype', 10, 2 );

Wooo so excited, this opens the door for so many possibilities