Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Display custom post type posts within the_content filter Reply To: Display custom post type posts within the_content filter

#160338
asiek
Participant

FOUND A SOLUTION
I remembered that you can add content inside of shortcodes.
So I created my own shortcode [textures_content]//

    add_shortcode( 'textures_content', 'textures_shortcode' );
function textures_shortcode( $atts ) {
    ob_start();
    $query = new WP_Query( array(
        'post_type' => 'textures',
        'posts_per_page' => -1,
        'order' => 'ASC',
        'orderby' => 'date',
    ) );
    if ( $query->have_posts() ) { ?>
            <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                <li>
                    <figure>
                        <?php the_post_thumbnail('thummy'); ?>
                        <figcaption>
                            <h3><?php the_title(); ?></h3>
                            <?php if ( has_post_thumbnail()) {
                            $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
                            echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >View Full Image</a>'; }?>
                        </figcaption>
                    </figure>
                </li>
            <?php endwhile;
            wp_reset_postdata(); ?>
    <?php $myvariable = ob_get_clean();
    return $myvariable;
    }
} 

Copied and pasted the shortcode and now it works perfectly!!!!!!