WordPress: How search a post for “post_content” wi

2019-06-24 19:26发布

As the title suggests, I'm trying to find a post through its post_content. How can I do it? Thanks

Example: SELECT * FROM DBname WHERE post_content LIKE '%phrase%'

标签: wordpress
2条回答
爷、活的狠高调
2楼-- · 2019-06-24 19:51

Alternatively, (and since it is specified in question) you can achieve this by actually using "WP_Query" class:

// The Query
$my_query = new WP_Query( array(
    'post_type' => 'post',
    's' => 'phrase'
));

// The Loop
while ( $my_query->have_posts() ) {
    $my_query->the_post();
    get_content();
    //...
}
查看更多
霸刀☆藐视天下
3楼-- · 2019-06-24 20:11

Something like this?

$result = $wpdb->get_results( "SELECT * FROM wp_posts WHERE post_content LIKE '%phrase%'" );
  if ($result){
    foreach($result as $pageThing){
      echo $pageThing->post_content;
    }
  }
查看更多
登录 后发表回答