2015-10-13 311 views

回答

0

它可以實現使用真棒WP查詢類的WordPress與搜索參數。例如以下查詢將搜索其中包含「hello」字的任何帖子,並根據需要顯示其帖子ID:

<?php 
    // 's' parameter is for search 
    $the_query = new WP_Query(array('s' => 'hello')); 

     if ($the_query->have_posts()) { 
      while ($the_query->have_posts()) { 
       $the_query->the_post(); 
    //now we can echo anything we want like e.g. IDs 
       echo get_the_ID(); 
     } 

     } else { 
       // no posts found 
     } 
     /* Restore original Post Data */ 
     wp_reset_postdata(); 

?>