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?
- What SQL Query to do a simple find and replace
- Return only Count from a wp_query request?
- Is there a way to list all used/unused WP templates?
- Differences between wpdb->get_results() and wpdb->query()
- simple sql query on wp_postmeta very slow
- How many WordPress SQL Queries per page?
- wpdb->prepare function remove single quote for %s in SQL statment
- Inserting Post Meta From SQL
- How to make an activities stream mixing posts and comments?
- SQL query equivalent to WP User Query
- 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
- $wpdb->get_var not returning a result
- cron job to auto delete posts of a specific post type older than x days
- Get posts by category with pure SQL query
- How to execute mulitple statement SQL queries using $wpdb->query?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Most effective use of DB querys
- Custom query to get terms from post ids
- Query WordPress database by registered date and role
- Get the timout value of a saved transient?
- Grouping related postmeta data via SQL query
- $wpdb->query() vs. $wpdb->get_results() vs. phpMyAdmin
- Mysql / WordPress killing my server with 80k users [closed]
- Slow meta_query with about 4 milion record on wp_postmeta
- 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?
- Select User by Joining Multiple Meta Value Results
- mySQL query. ORDER BY meta_key
- $wpdb doesn’t appear to work on page inside of a plugin
- wpdb_prepare with multiple or condition
- Strange string in console from wpdb query
- Using $wpdb->update but confused on the WHERE in and SET
- Update slug (URL) of pending posts via phpMyAdmin
- How to correctly pass values to wpdb->prepare()?
- My SQL function to change user_name
- You have an error in your SQL syntax – Help with query
- Make one query for adding entries to database
- Why is variable not working on custom sql query using wpdb?
- Get stock by custom meta field on all Woocommerce variable products
- MySQL variable in query
- How to execute a SQL-query which contains multiple queries using $wpdb->query?
- Alter a specific query on WordPress
- Advanced SELECT query with condtional statements
- 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
- SQL query to select posts from multiple categories
- 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
- Create table from array with prepare
- Plugin will sort users by usermeta
- problem with sql query in wordpress plugin
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- MySql Query very slow
- $wpdb->insert() does not Insert record in a table
- Attempt to improve WP search, can someone check my SQL query?
- Searching With Apostrophe
- WordPress Query wp-terms SLOW
- How to write: $wpdb->update having WHERE NOT value pair in the array
- WordPress SQL Issue not returning correct reselts
- Making a query to the DB using same parameters of loop
- Use mysql_query instead of $wpdb query
- Custom WordPress Table wpdb