0

Yesterday I implemented a shortcode, but now my comments and related posts stop appearing.

The source of a rendered page now only displays

            <div class="posts-group">
            </div>

instead of

    <div class="posts-group">          
      <div id="disqus_thread"></div>
    </div>

    <div class="posts-group"><h2>Looking for more articles?</h2>
       //RELATED POSTS
    </div>

Now the only difference is the use of the shortcode, so the "bug" has to be there, right? Only problem is.. I see nothing wrong with it.

shortcode in functions.php:

function get_products($atts) {
  ob_start();
  get_template_part('block-products-inline');
  return ob_get_clean();
}
add_shortcode('products', 'get_products');

the block-products-inline template part:

<br>    
    <p><i>Article continues below these four featured products!</i></p>

    <div class="posts-group inline-products">

        <h1>Featured store products</h1>

            <?php $catquery = new WP_Query( 'post_type=product&posts_per_page=4&orderby=rand' );
            while($catquery->have_posts()) : $catquery->the_post();
            ?>

            <a href="<?php echo get_post_meta($post->ID,'PRODUCT-url', true);?>">
                <article class="post home-post homeproduct">
                        <div class="post-thumbnail-img inline-products-hover">
                            <?php the_post_thumbnail('small-thumbnail'); ?>
                        </div>
                        <h2>
                            <?php the_title(); ?>
                        </h2>
            </a>        
                        <p>
                            <?php the_content(); ?>
                        </p>
                </article>

            <?php endwhile; ?>

    </div>
<br>

I'm hoping someone else sees/finds my problem as I haven't got a clue.

3
  • Where is block-products-inline.php? What is the full path? Where are you using the shortcode? Is it inside the post content as typical?
    – s_ha_dum
    Jan 6, 2016 at 14:48
  • block-products-inline.php is in the root theme folder, shortcode is used inside the post content
    – vlovsky
    Jan 6, 2016 at 14:53
  • Are you getting any errors?
    – s_ha_dum
    Jan 6, 2016 at 15:04

1 Answer 1

0

This is a bit of a guess, but you are running a secondary query inside the Loop (by way of the shortcode). That is going to alter some variables that subsequent code may depend upon, such as $post.

I am thinking that you need to add wp_reset_query(); after your secondary Loop in the shortcode-- right after the endwhile;

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.