0

I have tried this:

<?php 

$query = new WP_Query(
 array(
  'post_type' => 'my-post-type',
  'post_parent' => $parent_id
 )
);

while ($query->have_posts()) : $query->the_post(); 
                                                                                       
if (is_page_template('my-template.php')) {
    echo 'is my template';
 } 
                                               
endwhile;

?>

My template is in the theme's root and so is the template where I am placing the code.

2
  • What are you actually trying to check? The custom template used by the current post in the loop? Dec 6, 2021 at 14:52
  • Yes that's right, I want to loop through posts but only those using a certain template.
    – flinch85
    Dec 6, 2021 at 14:58

1 Answer 1

0

I managed to get the required result like this:

<?php
  $template = get_page_template_slug();

  if ($template === 'my-template.php') { 
   //do stuff
  }
?>

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.