First you need to get the identifiers, and then add these IDs to wp_query.
global $wpdb; $post_ids = []; // Get all the IDs you want to choose from $sql = $wpdb->prepare( " SELECT ID FROM $wpdb->posts WHERE ID > %d ", 555 ); $results = $wpdb->get_results( $sql ); // Convert the IDs from row objects to an array of IDs foreach ( $results as $row ) { array_push( $post_ids, $row->ID ); } // Set up your query $custom_args = array( 'posts_per_page' => 10, 'tag' => 'my-tag', 'post__in' => $post_ids ); // Do the query $custom_query = new WP_Query( $custom_args ); // the loop if( $custom_query->have_posts() ) : while( $custom_query->have_posts() ) : $custom_query->the_post(); echo get_the_title() . '<br>'; endwhile; endif;
source share