Site icon Hip-Hop Website Design and Development

the right way to use {custom} loop in the_content filter

Making an attempt to make use of the the beneath code for my CPT ‘state’ like add_filter('the_content', 'my_custom_loop'); however the trial and error shouldn’t be getting me anyplace. I can not use a single-{post_type}.php since i’m utilizing a drag and drop theme headway.

Replace: precise code I’m making an attempt to make use of in a performance plugin and it provides me a warning include-once with debug on or a clean white display

perform my_custom_loop() {
if( is_singular('state') && is_main_query() ) {
$taxonomy = 'state_cat';

  $phrases = get_the_terms($post->ID, $taxonomy);

  if ($phrases && ! is_wp_error($phrases)) : 


$terms_array = array();

foreach ($phrases as $time period) {
  $terms_array[] = $term->slug;
}

$my_query = new WP_Query(
  array(
    'posts_per_page' => 100,
    'post_type' => 'submit',
    'post__not_in' => array($post->ID),
    'category__not_in' => 418,
    'tax_query' => array(
      array(
        'taxonomy' => $taxonomy,
        'subject' => 'slug',
   'include_children' => false,
        'phrases' => $terms_array
      )
    )
  )
);
 //Shops html in buffer
 ob_start();
 if($my_query->have_posts()) :


   whereas($my_query->have_posts()) : $my_query->the_post(); ?>

    <div class="custom-loop clearfix">
            <div class="loop-thumb"><?php the_post_thumbnail('thumbnail'); ?></div>
            <div class="loop-content">
                <div class="loop-title"><?php the_title(); ?></div>
                <div class="loop-excerpt"><?php the_excerpt(); ?></div>
            </div>
    </div>
  <?php endwhile; wp_reset_postdata(); 


   endif; 

 endif; 
}
 //get buffer contents
 $output = ob_get_clean();

 return $output;
}
add_filter('the_content', 'my_custom_loop');

Thanks to your time.