After much trial and error I finally figured out a solution using mysqli. I consider it a acceptable solution since the query will only be run on plugin updates.
$mysqli = new mysqli();
$mysqli->connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$sql = "
DROP TRIGGER IF EXISTS {$wpdb->get_blog_prefix($site->id)}post_queue_insert;
CREATE TRIGGER {$wpdb->get_blog_prefix($site->id)}post_queue_insert BEFORE INSERT ON {$wpdb->get_blog_prefix($site->id)}posts
FOR EACH ROW BEGIN
INSERT INTO {$wpdb->base_prefix}post_queue (action_id, action_type, action_status, action_event, action_timestamp, sync_complete, SITE_ID) VALUES (NEW.ID, NEW.post_type, NEW.post_status, 'insert', UNIX_TIMESTAMP(now()), 0, {$site->id});
END;
";
$mysqli->multi_query($sql);
$mysqli->close();
Related Posts:
- How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
- wpdb get posts by taxonomy SQL
- Are database queries created using WordPress filters protected from SQL injection?
- What’s wrong with my $wpdb prepare?
- How do I see the mysql query generated by get_posts( $args )?
- wpdb query problem to access previous 3 days posts
- I can’t figure out what’s wrong with this statement. $wpdb->query update
- wpdb COALESCE won’t work
- Custom Query – Based on user input
- Get posts from category with custom query
- how to insert missing tags into the posts through mySQL?
- Valid SQL query return empty
- mysql query – how to escape apostrophe?
- $wpdb->prepare affecting the query?
- prepare function sql safe method
- Updating with $qpdb->query() always returns 0 rows affected
- How to return count of custom post type posts with a specific custom field value via $wpdb?
- WordPress Mysql query and Duplicate
- How do I query for posts by custom meta and those that have been stickied?
- Help with Related Posts Function
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- Delete oldest wordpress post (SQL query)
- SQL query to delete users with multiple meta keys and comments
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- Fastest and most efficient SQL query to check if UID exists
- How to make MySQL search queries with quotes
- $wpdb query for price in custom field value
- Run an update query in a function
- Wpdb generates too many queries
- Mysql query and odd results
- How to display SQL query that ran in query?
- How do you properly prepare a %LIKE% SQL statement?
- simple sql query on wp_postmeta very slow
- Custom $wpdb Query for Custom Post Type by Category
- Can’t pass table to $wpdb->prepare
- WordPress creating excessive joins on meta_query with search
- cron job to auto delete posts of a specific post type older than x days
- How to execute mulitple statement SQL queries using $wpdb->query?
- Most effective use of DB querys
- Query WordPress database by registered date and role
- Get the timout value of a saved transient?
- Grouping related postmeta data via SQL query
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- wpdb::prepare() isn’t working
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- wpdb_prepare with multiple or condition
- Update slug (URL) of pending posts via phpMyAdmin
- My SQL function to change user_name
- Why is variable not working on custom sql query using wpdb?
- Get stock by custom meta field on all Woocommerce variable products
- how would I create a custom query to get all users, and a related post based on a postmeta field?
- Help with MySQL to $WPDB query
- Alter query with posts_clauses to retrieve NULL values last
- Order by summing multiple values
- sql select query in wordpress ‘page’ [closed]
- wpdb->term_taxonomy count posts from both published and private posts?
- wpdb print all post meta
- Plugin will sort users by usermeta
- problem with sql query in wordpress plugin
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- Attempt to improve WP search, can someone check my SQL query?
- Searching With Apostrophe
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- Use $wpdb or other PHP script method to find/replace in WP database
- Custom Query returns array, but I can’t see it’s elements
- How to get INSERT errors from $wpdb?
- Ideas how to search & replace post_content when string contains a newline?
- SQL query to set posts in bulk based on the post content
- Query the WordPress database to get data together with replaced information
- WordPress SQL search, how to handle SQL Injection?
- Optimize slow SQL query for multiple meta values
- WordPress SQL query to tag all posts containing a specific word on title
- wpdb update multiple row?
- Formatting a date/time returned from a custom $wpdb query
- How to delete all images from code in all post_content
- Cannot get sql request from Query object?
- Customising the default wordpress search functionality
- Displaying data from custom table
- PHP Fatal error: Uncaught Error: Call to a member function insert() on null
- Nested select statements not working
- OR condition not working
- Trouble migrating custom post types from non-wordpress cms
- Exclude Posts from a Widget
- Use $wpdb->get_results with filter based on array
- Function returning queried meta value based on current post ID
- Custom MySQL Query for Post and Post Meta
- Slow query when joining wp_posts with a lookup-table?
- Custom WordPress SQL Query 4 posts per custom taxonomy
- learn to run wpdb class
- Access Tables with number prefix
- How to reference same column name but different table in custom db query
- Retrieving custom field array value through db query
- How to get one result using wpdb class?
- SQL Query : how copy all tags of post into their post content in wordpress by sql query
- Delete query won’t run
- Where can I find the SQL to get the most used information by wordpress database?
- 3 queries to update WordPress
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta