2014-02-20 2 views
0

wordpress의 get_terms() 함수에 이상한 문제가 있습니다.Wordpress get_terms 인수 전달 문제

<?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> 

은 아무 용어도 반환하지 않지만 $ x 대신 직접 값 1220을 사용하면 값을 반환합니다. 다음 코드는 제대로 작동하고 있습니다.

<?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> 

나는 다른 곳에서 용어 ID를 얻을 것이므로 변수를 사용해야합니다. 여기에 문제가 무엇인지 말해주세요.

답변

0

싱글을

$terms = get_terms("topics", 'hide_empty=0&parent=$x'); 

'

$a = 9; 
echo '$a'; // output = $a 
echo "$a"; // output = 9 
을 고려 $ 기호를 인쇄 할 따옴표 교체귀하의 경우

단지 따옴표 "

$terms = get_terms("topics", "hide_empty=0&parent=$x"); 

하거나 하나 (또는 ​​따옴표)로 문자열 변수를 concate

$terms = get_terms("topics", 'hide_empty=0&parent=' . $x); 

$terms = get_terms("topics", 'hide_empty=0&parent=$x'); 

변경

0

오히려 변수

의 가치를 보여주는 그대로

$terms = get_terms("topics", 'hide_empty=0&parent='.$x);