I've been using the following code to get a template part based on the parent term. It was working fine until I updated WordPress to v4.4 earlier today. Since updating if there is also a child term selected it no longer works to bring in the template part.

Any ideas? I'm tearing my hair out.


$terms = get_the_terms( $post->id, 'type', array( 'parent' => 0 ) );
$terms_slugs = array();
foreach( $terms as $term ) {
    $terms_slugs[] = $term->slug;

if( !empty($terms_slugs) ) :
  get_template_part( 'blocks/block', array_pop($terms_slugs) );
else : endif;


Edit: Solved it! Changing array_pop to array_shift. No idea what the difference is or why array_pop would suddenly stop working. Phew!

  • I'm assuming your file is: theme-name/blocks/block-termname? How does the term-slug look, can you give us an example?
    – Howdy_McGee
    Commented Jan 5, 2016 at 15:36
  • File is theme-name/blocks/block-written-in-stone and the term slug is written-in-stone
    – leanda
    Commented Jan 5, 2016 at 15:39
  • What does "if there is also a child term selected " mean? Where does this fail? With get_the_terms()? With get_template_part()? Can you narrow this down?
    – s_ha_dum
    Commented Jan 5, 2016 at 15:51
  • If the parent category is the only category selected then it works no problem, but if I select a second sub category (child) then it fails to use the template part. It's really odd, as this was working before I upgraded WP this morning.
    – leanda
    Commented Jan 5, 2016 at 15:53
  • 1
    Please do not edit the solution into the question.
    – s_ha_dum
    Commented Jan 5, 2016 at 17:55

1 Answer 1


leanda reports that the problem has been resolved:

Solved it by changing array_pop to array_shift.

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.