Most of my plugins including Contextual Related Posts and Top 10 run SQL queries in order to fetch information from the WordPress database. e.g. Contextual Related Posts pulls the related posts via an SQL query and Top 10 pulls the popular posts.

I usually tell many users who request support in the forums to install Query Monitor and check what the SQL generated by the plugin in. It also helps to run the queries in phpMyAdmin or a similar software to see what the outputs are.

In this post, I’ll explain how you can use Query Monitor to find the SQL that is generated by Contextual Related Posts.

Step 1: Install Query Monitor

If you don’t have Query Monitor installed, you can navigate to Plugins > Add New and search for Query Monitor. It should be the first plugin in the list. Hit Install and then Activate or Network Activate (if you’re using Multisite).

Once you install Query Monitor, you will notice a new menu item added to the admin bar at the top of your page. This item has several menu items as you can see in the top right portion of the above screenshot.

Step 2: Locate the Query

Navigate the post that you have noticed the problem on and then hit the new menu item and then select Queries. This will split your screen horizontally (or vertically) and you’ll see a set of menus to the left along with a complete set of queries.

Next select Queries by Component and from the component list pick Plugin: contextual-related-posts.

When you do this you’ll see all the queries generated by the plugin. You’ll note that as per the below screenshot, the Component dropdown will be populated. In order to find the main query, select WP_Query->get_posts in the Caller dropdown.

You can then use this query to either run it in phpMyAdmin or post in the forum in order to receive support.