Counting And Monitoring How Much Queries My Script Used

Actually there happens more than single query behind the scene. They are both for getting some needed data and also for updating or creating or inserting data. Say for post terms wp_insert_post() get those data by query. So, where you’re assuming that it should run 40,000 query it actually run more than that. Please have look here. This guy explained step by step beautifully how wp_insert_post() actually works.