Post type get short code with category slug (working)

PHOTO EMBED

Fri May 05 2023 13:41:02 GMT+0000 (Coordinated Universal Time)

Saved by @hamzahanif192

function flight_loop($atts)
{
    
    
    // It's a default value.
	$default = array(
		'category' => '',
	);
	// You will pass default value after that user define values.
	$button_attrs = shortcode_atts( $default, $atts );

    $arg = array(
        'post_type' => 'flight',
        'posts_per_page' => -1,
        'tax_query' => array(
        array(
            'taxonomy' => 'flight_category',
            'field'    => 'slug',
            'terms'    => $button_attrs['category'],
        ),
    ),
        );
        $flightPost = new WP_Query($arg);
    ?>
    <div id="mainflight " class="row">
    <?php if ($flightPost->have_posts()) : ?>
            <?php while ($flightPost->have_posts()) : ?>
            <?php $flightPost->the_post(); ?>
            <div class="singleFlight col-md-6">
                <?php the_post_thumbnail( 'full', array( 'class' => 'flightimg' ) ); ?>
                <h4><?php the_excerpt(); ?></h4>
                <h2><?php the_title(); ?></h2>
                <a href="#">Search For Flights <img src="<?php bloginfo('stylesheet_directory'); ?>/images/Arrow_right.svg copy 2.png" alt="Login"></a>
            </div>
            
            
            <?php endwhile; ?>
            <?php endif; ?>
</div>
<?php
    wp_reset_postdata();

}
add_shortcode('medical_flights_all', 'flight_loop');


content_copyCOPY