Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 542
Donovant Avatar asked Mar 13 '12 01:03

Donovant


People also ask

How do I find a post using like for a category name in WordPress?

Here is the code. $term_ids=array(); $cat_Args="SELECT * FROM $wpdb->terms WHERE name LIKE '%". $_REQUEST['s'].

How do I find post queries in WordPress?

query_posts() is a way to alter the main query that WordPress uses to display posts. It does this by putting the main query to one side, and replacing it with a new query. To clean up after a call to query_posts, make a call to wp_reset_query() , and the original main query will be restored.


1 Answers

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();
    //...
}
like image 190
maxime schoeni Avatar answered Nov 15 '22 06:11

maxime schoeni