I am facing a weird issue with get_terms() function of wordpress.
<?php $x=1220;
$terms = get_terms("topics", 'hide_empty=0&parent=$x' );
<ul class="ul1">
<?php foreach ($terms as $term) { ?>
<li><a href="<?php echo get_term_link($term->slug, 'topics'); ?>">
<?php echo $term->name; ?></a>
</li><?php }; ?> </ul>
is not returning any terms but when I use the value 1220 directly instead of $x, it is returning values. The following code is working properly.
<?php $terms = get_terms("topics", 'hide_empty=0&parent=1220' );
<ul class="ul1">
<?php foreach ($terms as $term) { ?>
<li><a href="<?php echo get_term_link($term->slug, 'topics'); ?>">
<?php echo $term->name; ?></a>
</li><?php }; ?> </ul>
I need to use variable as I will be getting term id from elsewhere. Please tell me what is the problem here.