Articles of posts where

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 running on every query, not just the main one. Given the following code, the code will be executed once on each […]

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(“-100 days”)) . “‘”; return $where; } add_filter(‘posts_where’, ‘smbd_cats_by_days’); It is working fine. But now I want to make this function generic. (ie) […]

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’ : ‘ASC’, ‘orderby’ => ‘ID’, // ID <= $post->ID ); I’ve been digging around in the codex with no luck. I can of course do this conditionally […]

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 returning the posts, here is how I’m doing it: $vars = $_GET[‘vars’]; $time = $vars[0]; $order = $vars[1]; if […]

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 posts from authors with that word also post who includes it either on their title or […]

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 table “lat_lng_post”. I’m able to search clinics within a specific distance using filter post_where in this way: […]

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, but, especially on older posts, the field will not always be set. Note that I’m doing […]

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 using today, and it’s working. add_action(‘pre_get_posts’, ‘my_search_price’); function my_search_price( $query ) { if ($query->get(‘maxprice’) != “” […]

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 pretty far and everything is working great. Except now I am stuck on how to include the […]

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 using which in theory I think should work, but really I have no idea on the sql and […]