2013-06-26 2 views
0

나는 WordPress의 내용으로 게시물을 얻으려고하고 있지만, 쿼리와 연결되지 않은 임의의 결과가 나타납니다. 어떤 아이디어?wordpress에서 콘텐츠로 게시물을 얻는 방법

$q='my query'; 
$query = new WP_Query('s = "'.$q.'"'); 
$gids = array(); 
if ($query->have_posts()) { 
    while ($query->have_posts()) { 
    $query->the_post(); 
    $gids[]=get_the_ID(); 
} 
} else { 
    // no posts found 
    } 
wp_reset_postdata(); 
// 
if (count($gids)>0){ 
//find random one 
    $rand = array_rand($gids); 
    $post_id=$gids[$rand]; 
    $post = get_post($post_id); 
    header('application/json'); 
    echo json_encode($post); 
} 
+0

같은 것이 http://wordpress.stackexchange.com – DanFromGermany

+0

어쩌면에 속할 수 없지만, 32,472 이상의 워드 프레스 여기에 질문을 태그하고 거기에만 33,293, 그것은 동등하게 될 수있다 그래서 여기에 집에와 마찬가지로 주장했다 – Anigel

답변

0

는이

$args = array(
    'post_content' => 'test', 
    'paged' => '1', 
    's' => 'post', 

); 
$query = new WP_Query($args); 

$gids = array(); 
if ($query->have_posts()) { 
    while ($query->have_posts()) { 
    $query->the_post(); 
    $gids[]=get_the_ID(); 
} 
} else { 
    // no posts found 
    } 
wp_reset_postdata(); 
// 
if (count($gids)>0){ 
//find random one 
    $rand = array_rand($gids); 
    $post_id=$gids[$rand]; 
    $post = get_post($post_id); 
    header('application/json'); 
    echo json_encode($post); 
} 
+0

아니, 그것은 작동하지 않습니다 ...하지만 난 http://stackoverflow.com/questions/9677039/wordpress-how-search-a-post-for-와 함께 작동하게 만들었어요. post-content-with-wp-query-class – Kubber

+0

커스텀 질의를 사용하고'WP_Query'를 제공했지만 문제가 커스텀 질의로 해결된다면 좋은 것입니다. 그것 :) –

관련 문제