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
- Meta_query compare operator explanation
- Can I force WP_Query to return no results?
- meta_query ‘compare’ => ‘IN’ not working
- Sorting: custom query with orderby meta_value_num THEN by title
- WP_Query and next_posts_link
- WP_Query with checkbox meta_query
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- Get array of posts from the current archive page loop
- How can I save an array from a random post sequence for later use?
- Meta Query with date and time on the same Day before given time
- In loop: posts have thumbnail AND other variables
- How to grab metabox value in wp_query meta_query key
- Add inline HTML to posts published within last 24hrs
- Move posts to top of WP_Query if in certain Taxonomy?
- How can I create a WP_Query that returns posts where one meta_value
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Implementing an OR statement to wordpress wp_query
- Get List of all the Authors
- WP_Query loop within WP_Query loop
- Refine search results using WP_Query
- How to pass many ids in post__in?
- How to show subcategories using loop?
- Add condition of user capability in WP_query
- How to make Meta Query case sensitive?
- Show Sticky Post at the top but do not show again in the loop?
- How do I run through a WordPress loop called from a filter function?
- Modify wp-query and sort by post meta key
- Out Of memory issue on post per page parameter
- Orderby listing issue
- Check if loop has any categories?
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- database query with more than a couple meta hangs and doesn’t complete
- get_template_part causes 500 error
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- WP_Query – Adding “offset” posts to the end of the loop
- Conditional operator OR not working with custom fields
- wp_query is showing posts from other categories
- Should I reset $wp_query?
- How does WP generate the default $query in WP_Query based on the URL?
- how to get category`s slug in WP_Query loop?
- Multiple meta_key ordering with pre_get_posts
- How I can repeat 2 HTML templates in a WordPress Query?
- Meta query with compare by more than 2 fields
- Offset WP_Query by negative 1
- WP_Query orderby random do not repeat infinite scroll – one loop
- Advise on Templates for Custom Queries
- meta_query returning excluded result
- Query WP Page for Buddypress Group Home [closed]
- $post in wp_query?
- How to pass the current content of $wp_query to a new page?
- meta_query weird behaviour, static int will work, but not user data
- Creating a query that get all posts but places meta items first
- How to separate two columns from one content on a page template?
- get_posts query is taking about 40 seconds to execute
- wp query to use both author id and meta_query
- WP_Query for a taxonomy value OR a custom post type meta field
- Meta query orderby meta_value_num sorting by role first
- Avoid removing duplicate posts
- Regarding a custom loop and output HTML tags
- Repeat array inside array through while loop
- What’s causing an infinite loop?
- pages shortcode filtering by category
- Second WP_Query loop shows data from main query
- Speed up WP_query with meta comparing dates
- Get post Number with local loop and template
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to show all the associated posts with specific date of data metabox?
- display post multiple times based on array of dates
- Problems with WP_Query, Loop, a condition and Posts per Page
- WP_Query secondary query failing
- Custom search (wp query by custom fields)
- Sorting is not working in WordPress WP_Query
- Add custom WP_Query after the first 3 posts
- Limit the number of posts from a specific category on index.php
- Why is WP_Query’s meta_query not filtering results?
- meta_query in wp_query not working as expected
- Query for page content, and query for posts on the same page?
- WP query with multiple custom meta not respecting orderby
- How to get rid of extra Untitled Article in html5 document outline when using new WP_Query?
- after refresh the id that shows correct in first time click, changes to 1
- Unexpected number of loops in while
- Passing a variable containing a comma separated list of values in a meta-query