2015-10-13 121 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(); 

?>