Google+
Shineyrock web design & consultancy

Shineyrock

blog

  • dislike -1 18

    Display the Last WordPress Query in 60 Seconds

    If you're working on a project that's built on WordPress, then you may find yourself in a situation where displaying the most recently executed query is useful. This is especially true if you're working on a large project with a team, or if you've inherited a large codebase from someone else, or if you're needing to debug the performance of a given template.

    In the following video, you will see how to write a custom function that hooks into the WordPress lifecycle to display the WordPress query that was run most recently.

    This particular function can be wrapped in a conditional that evaluates the presence and value of a query string variable to determine if the query should be displayed or not. This is helpful in debugging code in a staging environment.

    Rendering the Query

    If you're using a theme and the result of the query doesn't display correctly, then using a small snippet of CSS such as the one below may help:

    You may need to tweak these styles based on the theme that you're using, but this should be a good starting point.

    Want More WordPress?

    Remember, you can catch all of my courses and tutorials on my profile page, and you can follow me on my blog and/or Twitter at @tommcfarlin where I talk about software development in the context of WordPress.

    WordPress has an incredibly active economy. There are themes, plugins, libraries, and many other products that help you build out your site and project. The open-source nature of the platform also makes it a great option from which you can better your programming skills. Whatever the case, you can see what all we have available in the Envato Marketplace.

    As usual, please don't hesitate to leave any questions or comments in the feed below, and I'll aim to respond to each of them.

    Resources

    martijn broeders

    founder/ strategic creative at shineyrock web design & consultancy
    e-mail: .(JavaScript must be enabled to view this email address)
    phone: 434 210 0245

By - category

    By - date