Questions tagged [posts-where]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
58 views

Custom SQL query slows down when using multiple OR ... LIKE ... in posts_where filter

I have built a posts query that includes a custom table in search using the posts_join and posts_where filters. Now the customer wants me to include yet another custom table in the search, but doing ...
gl03's user avatar
  • 111
0 votes
0 answers
22 views

WP_Query's WHERE updated, but Search Results are not updated

I am pretty new to WordPress here, and I have seen the way to add condition into the query is by adding below inside functions.php: add_filter('posts_where', 'add_where'); function add_where( $where ) ...
Furanzu's user avatar
1 vote
1 answer
90 views

what are the checksums surrounding keywords in the SQL generated by WP_Query and do I need to use them too?

I am using posts_join and posts_where filters to include a custom table in a query. this page says I should "use whatever WordPress did to search the post title field to search my custom table fields ...
guardiancrescent's user avatar
0 votes
1 answer
251 views

How to exclude posts for current user

How can I hide posts that are in an array of ids in the usermeta for the current user in the main query. I can use post__not_in in meta_query but I do not know which option to use for only a specific ...
Alex's user avatar
  • 15
0 votes
1 answer
702 views

How Can I keep password protected posts in the json requests but not on frontend queries?

I am attempting to exclude password protected posts from any frontend loop - inspired by this post However, I have a custom angularjs admin theme that is activated when a user visits a certain post ...
friendlyfire's user avatar
1 vote
1 answer
553 views

How do I hide posts across all loops based on the value of a custom field?

I'm trying to dynamically hide posts across my entire site if the value of a custom field called distribution is "1". I've set up a meta box on the post editor screen to set the value of the field, ...
parasomnist's user avatar
9 votes
1 answer
12k views

How to modify posts_where filter only for the search query

I'm using posts_where filter in order to modify the user searches on a web, but i find out that some default widgets like the "more recent posts" uses this filter too and their behaviour are also ...
dtd93's user avatar
  • 93
1 vote
1 answer
602 views

Remove the post_content search from WHERE clause (and CONCAT sql function)

I've a custom table and by following the instructions on this page https://codex.wordpress.org/Custom_Queries I was able to modify the WHERE clause. function geotag_search_where( $where ){ if( ...
codeispoetry's user avatar
5 votes
1 answer
1k views

Order wp_query by calculated field

Hi I'm working on a store locator. I have a custom post "clinics" where I save clinic details (address,.., lat, lng). Each time I publish a new clinic I save post_id, lat and lng also in a custom ...
dstyle76's user avatar
2 votes
1 answer
2k views

Wp query show post by author name or post title or post content

I have to create a search query which allows me to filter all posts where author name and post titles or post content has the word from search textbox. So if i search wordpress it should list all the ...
star's user avatar
  • 31
0 votes
1 answer
279 views

Filtering posts by taxonomy and meta_value

I am writing a plugin that will hide and sort posts based on tags and postmeta. Products tagged "antique" that are out of stock will be hidden by default. So far, I can hide sold products, but when I ...
Chris's user avatar
  • 116
0 votes
0 answers
566 views

Avoid changing menu query with suppress_filters => false

I recently had to change qTranslate for qTranslate X since the former is not being updated. This broke my menu and after searching I found it was because qTranslate X sets suppress_filters to false. ...
Shane's user avatar
  • 831
0 votes
1 answer
1k views

Run posts_where and posts_join only on the main query

Using the pre_get_posts hook, I'm able to take $query as an argument. But on posts_where and posts_join hook, I receive the respective clauses and not the query. The problem is that the hook is ...
Morgan Delaney's user avatar
0 votes
1 answer
117 views

Help with SQL query, how to add taxonomie terms with value stored in options?

i need your help in making SQL What i have: custom post type ( company ) taxonomie ( category ) applyed to cpt ( and has ct section select field ) custom taxonomie ( section ) applyed to nothing In ...
Михаил Семёнов's user avatar
0 votes
1 answer
445 views

pre_get_posts or $where, which one to use?

i have a custom search widget, that is searching only one custom post type that contain a meta_key that is greater than or equal to 1, in which i am gathering post_id. of all of those post_id(s), i ...
Ray Flores's user avatar
5 votes
1 answer
567 views

Is there any difference between hooks posts_where with posts_join and posts_search performance wise?

I want to know which filter hook I should use that performs faster. I did try both several times and I noticed that posts_search is a bit faster than using the combination of posts_where and ...
Gixty's user avatar
  • 1,097
1 vote
1 answer
4k views

How to use filter hook posts_join for querying taxonomy terms in posts_where?

For the last few hours, I have been trying to use the filter hooks posts_where and posts_join to search for posts based on taxonomy terms, in this case, the taxonomy is 'category' and the term is '...
Gixty's user avatar
  • 1,097
2 votes
1 answer
6k views

How to search for posts IN OR title OR content OR author?

I have looked at many posts and questions regarding searches for custom meta, but I want to search for posts and include those if the search query matches an author name. I have come up with the ...
Gixty's user avatar
  • 1,097
0 votes
1 answer
2k views

Use posts_where to exclude posts ids from wp_query

I want to use posts_where to exclude an array of posts ids from all queries in my site. The array containing the posts ids depends on the user that is logged in. Can someone please tell me how to ...
Gixty's user avatar
  • 1,097
0 votes
1 answer
861 views

Custom post type filter by post meta - not returning correct counts

I have a custom post type product. And what I did, I made a custom filter function based on the custom post's meta data using posts_where filter. It's working but I noticed the post count is not ...
neil.odiaz's user avatar
0 votes
1 answer
1k views

using posts_where for meta data on pre_get_posts

Let's say you have some code which filters posts by using pre_get_posts e.g. add_action( 'pre_get_posts', 'be_exclude_category_from_blog' ); function be_exclude_category_from_blog( $query ) { ...
patrickzdb's user avatar
7 votes
2 answers
46k views

Prevent pre_get_posts filter on specific post type

I am running into one issue with pre_get_post filter. Actually I have 4 post types. Post, Pages, Events, and Venue. I created one custom field called city for event and venue post type. When ...
Shaikh Aezaz's user avatar
2 votes
1 answer
2k views

How do I create my own nested meta_query using posts_where / posts_join?

Some of my posts (not all) have a price as a meta key/value. Today I use the pre_get_posts action so that my users can search for prices that are between a certain value. This is the code that I'm ...
PappApp's user avatar
  • 23
1 vote
1 answer
512 views

posts_where Fails with More than One Custom Field in Query

Querying either of the 2 fields individually gives the expected result (posts are displayed). But, when both fields are included in the query (ex = 'foo' and 'bar' shown in below example), then no ...
edt's user avatar
  • 113
5 votes
2 answers
773 views

Extending WP_Query — Optimise SQL query

I'm storing posts, a user follows in a custom table that has the columns id, post_id and user_id. To fetch posts that a user follows I have extended the WP_Query as follows: class ...
John's user avatar
  • 1,449
0 votes
1 answer
4k views

apply custom where to the default $wp_query

I can read on the docs that if I need to perform a custom WHERE on WP_Query I need to do the following: // Create a new filtering function that will add our where clause to the query function ...
Fabrizio Regini's user avatar
1 vote
1 answer
991 views

Get Posts updated or published within the last x hours

Okay, I'm trying to get posts that have been published within the last x amount of time, options being 8, 24 or 72 hours. I have the variables being passed to my featureHandler.php via ajax, then ...
Joshua Richards's user avatar
2 votes
1 answer
169 views

When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?

This question is a follow up to a question I recently asked. I've implemented what seemed to be the only solution, and it seems to work (YAY!). I just need to verify that: This is really the only ...
Dan's user avatar
  • 887
0 votes
2 answers
5k views

Using dynamic conditions in 'posts_where' filter

I have the following code which gives be posts that are published in the last 100 days function smbd_cats_by_days ($where = '') { $where .= " AND post_date < '" . date('y-m-d', strtotime("-...
Sudar's user avatar
  • 809
2 votes
2 answers
2k views

Custom time range for the posts_where filter

I'm creating a function that displays the most viewed posts and would like to be able to show posts based on how old they are. Modifying the query is not really a problem. But since I can't pass any ...
John's user avatar
  • 335
4 votes
1 answer
3k views

Search ONLY by meta key / meta values

I'm almost there on this one. On functions.php i have this: function base_home_product_post_type( $query ) { if($query->is_search() && $_POST['box'] == 'sku') { $query->...
moraleida's user avatar
  • 2,245
4 votes
0 answers
195 views

Custom query incorrectly returning everything [closed]

I'm missing something somewhere, but I cannot connect the dots. Everything outputs properly except that the query returns everything from the DB, not just posts. Can anyone spot a reason for this ...
CrazyQuery's user avatar
1 vote
1 answer
3k views

Compare post-IDs within WP_Query? (Less than / Greater than)

Can I use WP_Query to only query posts less than (or greater than) a given post ID? $filtered_query_args = array( 'post_type' => 'projects', 'order' => $prev_next=='next' ? 'DESC' : '...
Zach Lysobey's user avatar
1 vote
1 answer
2k views

Including Custom Meta with posts_where query

I have been looking around to see how to do this but the solutions i've found don't seem to be working for me. I'm making an AJAX powered search for some wordpress custom post types. I have got ...
Ralphonz's user avatar
  • 324
1 vote
2 answers
2k views

Only retrieve posts where post_excerpt has been filled out

I'm trying to use get_posts to only return posts that have an excerpt. Done lots of searching and have been trying to use "posts_where" filter on the query but my SQL is lacking. This is what I'm ...
patnz's user avatar
  • 1,459