Skip to main content
added 12 characters in body
Source Link
pg.
  • 161
  • 1
  • 6

Hi I'm using WP query in WP 6.1.1 like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist, this isn't super relevant but it's complicated to write in MySQL so it's why I am not just writing it out:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ]; 

Then I query like this:

$posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

UPDATE

I added 'search_columns' to the array along with 's' like this:

$posts_where['s'] = $value; $posts_where['search_columns'] = [ 'post_content', 'post_name', 'post_title', ]; 

but I still get the same query:

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_excerpt LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_content LIKE '{[long string]}SEARCH{[long string]}'))) AND ((wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private'))) ORDER BY wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}' DESC, wp_posts.post_date DESC 

Hi I'm using WP query like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist, this isn't super relevant but it's complicated to write in MySQL so it's why I am not just writing it out:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ]; 

Then I query like this:

$posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

UPDATE

I added 'search_columns' to the array along with 's' like this:

$posts_where['s'] = $value; $posts_where['search_columns'] = [ 'post_content', 'post_name', 'post_title', ]; 

but I still get the same query:

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_excerpt LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_content LIKE '{[long string]}SEARCH{[long string]}'))) AND ((wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private'))) ORDER BY wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}' DESC, wp_posts.post_date DESC 

Hi I'm using WP query in WP 6.1.1 like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist, this isn't super relevant but it's complicated to write in MySQL so it's why I am not just writing it out:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ]; 

Then I query like this:

$posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

UPDATE

I added 'search_columns' to the array along with 's' like this:

$posts_where['s'] = $value; $posts_where['search_columns'] = [ 'post_content', 'post_name', 'post_title', ]; 

but I still get the same query:

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_excerpt LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_content LIKE '{[long string]}SEARCH{[long string]}'))) AND ((wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private'))) ORDER BY wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}' DESC, wp_posts.post_date DESC 
added 107 characters in body
Source Link
pg.
  • 161
  • 1
  • 6

Hi I'm using WP query like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist, this isn't super relevant but it's complicated to write in MySQL so it's why I am not just writing it out:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ];   

Then I query like this:

$posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

UPDATE

I added 'search_columns' to the array along with 's' like this:

$posts_where['s'] = $value; $posts_where['search_columns'] = [ 'post_content', 'post_name', 'post_title', ]; 

but I still get the same query:

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_excerpt LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_content LIKE '{[long string]}SEARCH{[long string]}'))) AND ((wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private'))) ORDER BY wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}' DESC, wp_posts.post_date DESC 

Hi I'm using WP query like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ];   $posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

UPDATE

I added 'search_columns' to the array along with 's' like this:

$posts_where['s'] = $value; $posts_where['search_columns'] = [ 'post_content', 'post_name', 'post_title', ]; 

but I still get the same query:

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_excerpt LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_content LIKE '{[long string]}SEARCH{[long string]}'))) AND ((wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private'))) ORDER BY wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}' DESC, wp_posts.post_date DESC 

Hi I'm using WP query like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist, this isn't super relevant but it's complicated to write in MySQL so it's why I am not just writing it out:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ]; 

Then I query like this:

$posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

UPDATE

I added 'search_columns' to the array along with 's' like this:

$posts_where['s'] = $value; $posts_where['search_columns'] = [ 'post_content', 'post_name', 'post_title', ]; 

but I still get the same query:

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_excerpt LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_content LIKE '{[long string]}SEARCH{[long string]}'))) AND ((wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private'))) ORDER BY wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}' DESC, wp_posts.post_date DESC 
added 687 characters in body
Source Link
pg.
  • 161
  • 1
  • 6

Hi I'm using WP query like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ]; $posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

UPDATE

I added 'search_columns' to the array along with 's' like this:

$posts_where['s'] = $value; $posts_where['search_columns'] = [ 'post_content', 'post_name', 'post_title', ]; 

but I still get the same query:

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_excerpt LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_content LIKE '{[long string]}SEARCH{[long string]}'))) AND ((wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private'))) ORDER BY wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}' DESC, wp_posts.post_date DESC 

Hi I'm using WP query like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ]; $posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

Hi I'm using WP query like this:

 $posts_where = [ 'post_type' => 'page', 'posts_per_page' => - 1, ]; 

If there are search and status inputs I use those:

 $posts_where['s'] = $search; $posts_where['post_status'] = $status; 

And I add in meta queries based on input too if they exist:

$posts_where['meta_query'][] = [ 'key' => 'content_variations', 'value' => '%', 'compare' => 'LIKE', ]; $posts_query = new \WP_Query($posts_where); $posts = $posts_query->posts; 

I want to change the search so that it will get posts where the value of $SEARCH can also match on post_name as well as title and content. I can see that the query that S makes is:

AND (((wp_posts.post_title LIKE '%[SEARCH]%') OR (wp_posts.post_content LIKE '%[SEARCH]%')) 

is there a way in WP query (i.e. not just writing out the query) to add OR (wp_posts.post_name LIKE '%[SEARCH]%') to that?

UPDATE

I added 'search_columns' to the array along with 's' like this:

$posts_where['s'] = $value; $posts_where['search_columns'] = [ 'post_content', 'post_name', 'post_title', ]; 

but I still get the same query:

SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_excerpt LIKE '{[long string]}SEARCH{[long string]}') OR (wp_posts.post_content LIKE '{[long string]}SEARCH{[long string]}'))) AND ((wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private'))) ORDER BY wp_posts.post_title LIKE '{[long string]}SEARCH{[long string]}' DESC, wp_posts.post_date DESC 
Source Link
pg.
  • 161
  • 1
  • 6
Loading