Pallas-Insight-Shortcode

PHOTO EMBED

Sat Oct 15 2022 17:15:59 GMT+0000 (Coordinated Universal Time)

Saved by @omnixima #php

// Shortcode [insight_posts category='' number='']

function insight_posts_shortcode( $atts, $content = null ) {
    loadmoreinsights_scripts();
    $atts = shortcode_atts(
        array(
            'uid' => '',
            'category' => '',
            'number' => '-1',
        ),
        $atts,
        'insight_posts'
    );

    $args = array(
        'post_type' => 'insight',
        'post_status' => 'publish',
        'posts_per_page' => $atts['number'],
        'orderby' => 'date',
        'order' => 'DESC',
        'meta_query' => array(
            array(
                'key' => 'insight_category',
                'value' => $atts['category'],
                'compare' => '='
            )
        )
    );
    $insight_posts_query = new WP_Query( $args );
    ob_start(); ?>

    
    
    <?php
    if ( $insight_posts_query->have_posts() ) { ?>
        
        <div id="<?php echo $atts['uid']; ?>" class="insights-post-wrap">
        
        <?php while( $insight_posts_query->have_posts() ) { $insight_posts_query->the_post(); ?>
        
            <div class="insights-post">
                <div class="insights-post-date"><?php echo get_the_date(); ?></div>
                <?php if(get_field('insight_pdf')) { ?>
                    <div class="insights-title-link"><a target="_blank" href="<?php the_field('insight_pdf'); ?>"><h3 class="insights-post-title"><?php the_title(); ?></h3></a></div>
                <?php } else { ?>
                    <div class="insights-title-link"><a href="<?php the_permalink(); ?>"><h3 class="insights-post-title"><?php the_title(); ?></h3></a></div>
                <?php } ?>
                <?php if(get_field('video_html')) { ?>
                    <div class="insights-post-video"><?php the_field('video_html'); ?></div>
                <?php } ?>
                <div class="insights-post-exceprt"><?php the_field('insight_synopsis'); ?></div>
                
                <?php if(get_field('insight_pdf')) { ?>
                    <div class="insights-post-link"><a target="_blank" href="<?php the_field('insight_pdf'); ?>">Learn More..</a></div>
                <?php } else { ?>
                    <div class="insights-post-link"><a href="<?php the_permalink(); ?>">Read more..</a></div>
                <?php } ?>
    
            </div>

        <?php } ?>
        
        </div>
        <?php
        wp_reset_postdata();
    } else {
        
        echo '<p>Nothing found</p>';
    }
    return ob_get_clean();
}

add_shortcode( 'insight_posts', 'insight_posts_shortcode' );
content_copyCOPY