You can use prepare:
global $wpdb;
$post_ids = [];
$last_id = 350;
$query = $wpdb->prepare(
"
SELECT ID
FROM $wpdb->posts
WHERE ID > %d
", $last_id );
$results = $wpdb->get_results( $query );
// it will convert the IDs from row objects to an array of IDs
foreach ( $results as $row ) {
array_push( $post_ids, $row->ID );
}
//now you can set up your query
$custom_args = array(
'posts_per_page' => 100,
'post__in' => $post_ids
);
$custom_query = new WP_Query( $custom_args );
if( $custom_query->have_posts() ) :
while( $custom_query->have_posts() ) : $custom_query->the_post();
echo get_the_title() . '<br>';
endwhile;
endif;
Note: You can change condition as per your requirement >, >=, <, <=
etc.
Related Posts:
- Display products from specific category in shop page
- Exclude post on loop by multiple meta key value
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Query sticky posts with thumbnails
- WP_Query on custom field and order results
- Any number in meta key (wp query)
- Array as ‘key’ in WP_Query
- How to provide meta_key array to wp_query?
- Wp_query with 2 meta keys and array of meta values
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- WP_Query not returning correct result with meta_query parameter
- show most viewed post
- Meta Query if Values Don’t Exist
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- Get post count of current loop when using multiple queries on one page
- compare meta_query in get_posts arguments
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Query by meta_key and order by meta_value_num return orderby date
- WordPress altering my custom query, How to fix it?
- Looping through tabular data
- Show default content if custom WP_Query has no posts
- Order by meta_key in custom post type doesn’t affect the query
- How to create/modfiy WP_Query to search in post title OR custom field?
- Display featured products through custom loop in WooCommerce 3 [closed]
- Multiple WP_Query loops with Pagination Not Working
- Multiple meta queries but arrange by specific meta value order
- Order Posts by meta value AND published date
- WooCommerce Only OnSale Products Loop Snippet [closed]
- ACF – Get lowest & highest value from field
- What format does the meta_query TIME type require?
- WP_Query filter and order by meta ordering by wrong joined table
- WP_Query last five posts, simply ordered by meta_value
- What is the random string I am seeing when I use get_query_var?
- WP_Query condition affects posts_per_page count
- Custom Search Not Consistent with Results
- Display both standard posts in a specific category along with a custom post type in a single loop?
- Orderby is working with one query but not with other
- meta_query in WP_Query value is not accepting array
- 1/3 of posts different class
- Changing sort order for presentation by Jetpack infinite scroll
- Two loops on archive page
- How to order posts by title after they have already been sorted by category
- get posts by meta_key from inside key of post meta
- Help optimizing slow WP_Query with meta_query
- meta_value_num not ordering all items
- Meta Queries – should nesting work after WP 4.1?
- Filter and Order by Multiple Custom Meta Values
- Meta Query relation “AND” then set array accordingly
- WordPress | Date not always appear [duplicate]
- Query with meta_query and tax_query together not working properly
- Is_single() conditional tag returns null in query
- Is it possible to query a custom field where the value is between two fields?
- Filter posts by comparing custom meta value against postdate
- Adding a html class based on post count
- Posts in loop all show the same author when there are many authors
- Multiple Rows in a using wp_query
- meta_query fails to compare on values containing apostrophes
- If have posts a week old, display, else display a different loop
- Create a page template for “top rated posts” but show full content and not just a list
- Daily drip of posts – based on user ‘startData’ – ordered oldest to newest
- How to add tax_query to $args with concatenation
- Check if searched number is within the post meta value
- WP ForLoop to compare meta information of posts to determine what post to display
- WP Query / Meta Query [duplicate]
- Query posts by searching for a string in a meta field
- Search.php – return number of results but cannot loop through
- Creating ‘posts page’ loop based on the page itself
- Query multiple post types, but different order for each
- Query ACF relationship field – Comparator IN – Value array
- Combine query in WP_User_Query()
- Multiple nested meta queries
- How can I modify the query by adding to the existing query?
- Custom wp_query inside a conditional stament inside a template part doesn’t work: why?
- WordPress Query custom ordering by temporary variable
- Check the stored / cached WP_Query with transients on post change
- New template file does not load category-specific post
- Comparing Meta Field date in WPQuery using Meta_Query?
- How to create better WP_Query to look for date time which is anywhere between two meta values?
- Custom query for custom post type not getting correct post ID
- Query post with content only
- Multiple meta_query not working
- compare for multiple meta values for same key in wp_query
- datetime picker, timestamps and meta queries
- WP_Query with meta_query won’t orderby
- Why is my query not giving results?
- Continue loop after $queryObject
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- Using custom field as ‘orderby’ value causing post grouping by publish date
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- List ALL posts within last week from current category on category page
- loop through custom post types with meta data
- Looking for a way to exclude frontpage and nav menu from query filter
- Using Query In Post Type Archives
- the_excerpt() not working in custom archive
- Get posts by meta value except one post [closed]
- WP_Query by meta key not returning any posts
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- WP Query – Show custom posts only if user contain some user meta
- How do I subquery with custom meta fields?