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

Wordpress

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

Best Answer

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();
    //...
}
Related Topic