WordPress: How search a post for “post_content” with “wp_query” class?

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%'

Related posts

Leave a Reply

2 comments

  1. 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();
        //...
    }
    
  2. 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;
        }
      }