2012-08-19 6 views
0
필터로 tag_id를 사용하여 워드 프레스에 다음 쿼리를 구축하는 동안 나는 문제를 데

는 : 내가이기 때문에WP_Query 및 태그 ID

<?php 
     $the_query = new WP_Query(array ( 
     'posts_per_page' => '-1', 
     'tag_id' => '' 
     )); 
     while ($the_query->have_posts()) : $the_query->the_post(); 
    ?> 

당신이 볼 수 있듯이, "tag_id"값이 비어 작동하므로이 에코가 값을 반환

 <?php echo of_get_option('slideshow-tags', 'no entry'); ?> 

하지만 PHP는 오류를받지 않고 쿼리에이 적응하는 방법을 모른다 : 여기에서 값을 검색하려고합니다.

내가 시도 :

<?php 
     $the_query = new WP_Query(array ( 
     'posts_per_page' => '-1', 
     'tag_id' => 'echo of_get_option('slideshow-tags', 'no entry');    ' 
     )); 
       while ($the_query->have_posts()) : $the_query->the_post(); 
    ?> 

그러나 그것은 작동하지 않습니다. 나는 뭔가 명확한 것을 놓치고 있다면 나에게 맨손으로 PHP를 잘 아는 사람이 아니다.

고마워요!

요한은

는 편집 : 여기

나중에 참조 할 수 있도록 대답이를 사용하는

 <?php 
     $the_query = new WP_Query(array ( 
     'posts_per_page' => '-1', 
     'tag_id' => of_get_option('slideshow-tags', 'no entry') 
     )); 
     while ($the_query->have_posts()) : $the_query->the_post(); 
     ?> 

답변

1

당신은 echo에 반환하지 않습니다 값이 of_get_option 인 경우 배열에서 사용하고 싶습니다.

$the_query = new WP_Query(array( 
    'posts_per_page' => -1, 
    'tag_id' => of_get_option('slideshow-tags', 'no entry') 
)); 

// Now just do the loop... 
+0

Joseph Silber에게 감사드립니다. 나는 당신의 코드를 시도하고 매력처럼 일했다 :) – Johann

1

시도는 :

$code_to_display = of_get_option('slideshow-tags', 'no entry'); 
'tag_id' => '$code_to_display' 
+0

안녕하세요, 귀하의 답변 Vasilii에 대해 감사드립니다. 그러나 요셉이 말한 것은 사실이며이 질문에 대한 답을 제공합니다. – Johann

관련 문제