I ended up using something like this:
function filter_where( $where="" ) {
global $post, $prev_next;
$the_ID = $post->ID;
$where .= " AND wp_posts.ID ";
$where .= $prev_next=='next' ? "< $the_ID" : "> $the_ID";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$nextProjQuery = new WP_Query( $filtered_query_args );
remove_filter( 'posts_where', 'filter_where' );
Related Posts:
- Best Practice for PHP
- Include WP_Query in my own PHP file?
- AJAX / Read More: multiple check_ajax_referer() and wp_create_nonce() not working independentely
- Display certain amount of posts on taxonomy archive page
- Result of Custom WP_Query appears on 404 Page (but result are found!)
- Show only one post for each author ( Page loads too slow )
- how to display active, upcoming and past event with featured listing with pagination
- Get list of WP Updates Across Sites
- what is diference wp_get_attachment_url / wp_get_attachment_src / get_post_thumbnail_id?
- Modern Tribe Calendar wp-query with meta query not working at all
- WP_Query sort using multiple numeric meta values
- WordPress WP_Query() Not working properly
- How to get to a specific position in wp_query?
- Get category name from custom loop and echo it once
- WP_Query loop, does not display special characters in title correctly
- Remove query string specific key value
- Hide post if matches current month and year
- Use WP_Query in shortcode
- Why is variable not working on custom sql query using wpdb?
- Random order of WP_Query results with highest meta value
- Using foreach loop breaks
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- Get users that likes the post
- inserting a post from an extern php file but post content doesn’t show on wp site
- WordPress theme options error
- WP_Query fails despite having 1 post
- Create a Blog Template Page
- Exclude posts with specific metadata from search?
- Display an image if odd number of posts in grid
- Why doesn’t PhotoSmash plugin play well with wp_query?
- WP_Query: getting posts where custom field exists
- How to show meta value code HTML after x paragraph
- Form search query – displaying ACF “Post Object” field as results
- get_the_ID() doesnt work
- Custom route and query
- change the default order of posts only for specific categories
- Getting posts to exclude from array
- extract serialized array to use for wp-query
- How can I split my query result in 2 arrays?
- WP_Query() load selected post
- How to get post category list as select in front-end?
- Order a WP_Query by meta value where the value is an array
- How do I check if there is a tag in the title
- Using multiple variables to assign categories to an array
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- Let current user know pending posts counts using wp_query
- get_terms with specific id order
- WP_Query for woocommerce products with a pattern as a post_title
- “pre_get_posts” orderby custom date field in different format?
- WordPress Search Ajax + Isotope + InfiniteScroll
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- wp_query – Exclude the first thumbnail from lazy loading on archives
- How to call my PHP function with AJAX ? wp_query
- Ajax filter with loadmore button
- Usermeta data unserialize, extract and display in table in WordPress
- Query on a repeater date (acf)
- Delete post meta by serialized meta value
- can I extend the WP_Query class to deal with ‘duplicate’ posts created by joining to wp_posts?
- Trying to get pagination working on WP_Query() post grid
- Check the database for a postmeta field
- WP_Query To Display Product Of Brand On Taxonomy Page
- Combine multiple queries, array_unique returns nothing
- How to display last whole post on the homepage
- wordpress query returning unexpected results
- Custom Post type Ajax search results
- Display only upcoming events / Show all events when archive year is selected
- wp_query beginner
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- How can I display a query in a page?
- For each 3 posts, show a different post type
- Add post class in custom loop (WP_QUERY)
- WooCommerce – Print Processing orders [closed]
- List of child pages fetch next results at link click
- Query category-specific, paginated posts and allow viewer to change sort order
- wordpress is_main_query() breaks
- Why does WP_Query show only the same post even with different categories and endwhile?
- How to get category pages to look like a certain archive page?
- show/hide attachments
- Post Title Not showing up
- Advanced Taxonomy query, with 3 post types
- reorder a WP_Query, using a dropdown
- Custom query_posts() parameter
- WP_Query based on another query on the page
- How to modify this function to exclude also the post belonging to a specific category?
- Show post like this image in my newssite [closed]
- Display biography post for today’s birthday person
- Changing regular db connection to $wpdb
- How do I run the following script from my articles page?
- XML WP_Query problem in PHP 8.0 and 8.1
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Three different queries on same page
- How to sort search result by post_title, then by post_content
- How do I display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- Show post in elementor based on views and specific category with query id feature in elementor
- AND and OR in my CPT search query depending on checkbox
- External WP_Query call from PHP crashed after version update
- Developing a “fallback” for empty wp_query results based on post dates