My solution to the problem:
$prepare = array();
$in = implode(',', array_fill(0, count($product_ids), '%d'));
foreach ($product_ids as $ids){
$prepare[] = $ids;
}
$prepare[] = "post";
$prepare[] = $num;
$results = $this->db->get_results($this->db->prepare("SELECT ID, post_title FROM {$this->db->posts} WHERE ID NOT IN({$in}) AND post_type=%s ORDER BY ID DESC LIMIT %d", $prepare));
Related Posts:
- How to use $wpdb to delete in a custom table
- get_results on large datasets
- Is there a (better) way to access $wpdb results?
- Using $wpdb generates DB error
- How do you use prepare when asking for a list of id’s
- how to execute different sql query in non-sanitized $wpdb->get_results function
- WPDB update row with != in where clause
- How to update records using $wpdb?
- Need help writing a $wpdb query
- show badge with count for pending items in custom post type
- WP Sql query multiple where clause
- WordPress SQL query – returning ‘true’ ‘false’ or ‘null’
- Modify the structure of data returned by $wpdb
- Syntax for $wpdb->prepare when searching in two columns
- Confused by $wpdb->prepare
- How to display user_nicename and usermeta values by custom query in WordPress?
- Optimizing WordPress Queries – Removing Group By ID
- How can I combine one field using wpdb and group by?
- $wpdb->prepare with ON DUPLICATE KEY UPDATE
- how to use $wpdb->prepare to update a custom table
- WPDB Placeholders and second argument for prepared statements
- Increment integer field in database when WHERE needs to be dynamic [closed]
- Custom SQL query ORDER BY term_order
- Custom $wpdb returns unexpected time based results
- How to left join meta in queries [closed]
- wpdb->get_row is selecting the variable as a column name
- CREATE TABLE with dbDelta does not create table
- $wpdb query outputs php code instead of executing it
- wpdb query not working
- WordPress wpdb->insert returns int(0) => doesn’t insert anything, no errors!
- WPDB SQL Ignore `post_status` Parameter
- how to list all post that are in the custom taxonomy using $wpdb
- WPDB SQL query SELECT from category
- How to use WHERE NOT EXISTS query to avoid duplicate entry using $wpdb to save in custom table?
- Creating an Angular factory from custom database table
- wpdb->update update the entire table instead of one row
- How do I update post based on meta_key in another table?
- Custom database query to validate data
- Alter the main search query to search posts by coauthor user name
- Creates only one table and not the other
- Protect custom form from SQL injection
- looking for a way to allow users to backup the plugin db data(save as)
- SQL Query to select post title & post ID from a particular category
- Get comments after specific date
- query using wpdb in wordpress gets me no result
- Get count of rows based if column exists in two different tables
- query_vars doesn’t return query string (trying to get data from $wpdb)
- Matching database content types to PHP types
- Use wpdb->prepare for `order by` column name
- wpdb->prepare function remove single quote for %s in SQL statment
- Saving custom form data into database
- wp-content/db.php : where is this file?
- $wpdb->get_results() returns good result only in first foreach iteration
- $wpdb->insert – inserting multiple rows
- WPDB->insert with special characters
- $wpdb->prepare not working with update table prefix
- How to use prepare to query with variables
- Use $wpdb in wordpress theme files
- get posts and postmetas in assoc array
- wpdb->get_row() / get_results – is it possible to return an object instances of my own class?
- Problem in creating table through plugin code
- $wpdb – do you have to use foreach even if there will always only be one result?
- Replicating the WP_Query ‘s’ param with $wpdb
- wpdb_prepare with multiple or condition
- $wpdb->insert query changes to SHOW COLUMNS query Output
- Fixing wpdb->get_results and wpdb->prepare?
- How does the WXR file differ from the WPDB?
- What’s wrong with my $wpdb prepare?
- Get stock by custom meta field on all Woocommerce variable products
- Display fields as values in array from external SQL DB
- What is wrong with this wpdb update?
- Constructing a dynamic WPDB query with multiple LIKEs
- Counting posts with argument without retrieving the posts
- Create new database through static page code
- Use $wpdb or other PHP script method to find/replace in WP database
- WordPress “wpdb->update” – Append Text Value
- Need help converting get_user_meta [keys] into own array
- Can’t call WPDB inside RSS template
- wpdb prepare sql problem
- Query and get meta as object(stdClass) on wp postmeta table?
- How do I query a table?
- check that the data exists before sending it to wpdb
- no result returns when using $wpdb->get_results with where clause
- Customising the default wordpress search functionality
- SQL queries to another wordpress site
- PHP | left join avg query give me Array()
- update not working using wpdb
- get_posts() SQL Injection
- og:image functions.php
- $wpdb select returns empty array
- Show error messages to a user when database insert fails
- Intermittent problem writing update_user_meta
- How to get specific table by current user login
- Combine posts and postmeta
- WPDB delivers wrong results from complex queries
- I can’t write in my DB using $wpdb->insert
- wpdb select from using array as search parameters
- Can’t get expected result from a wpdb query
- selecting row using wpdb which contain special symbols
- Query Problem in Clustom Plugin