Skip to content

Instantly share code, notes, and snippets.

@quasel
Forked from elimn/functions.php
Created September 3, 2018 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quasel/dc5600cd0192769255ad0d8c47b7b922 to your computer and use it in GitHub Desktop.
Save quasel/dc5600cd0192769255ad0d8c47b7b922 to your computer and use it in GitHub Desktop.
MT | TEC | Tribe Query Debug
<?php
// Checks the URL for the debug parameter
// example.com/event/event-name/?tribe_query_debug=true
function tribe_events_pre_get_posts_dumper ($query) {
$show_debug_info = isset($_GET['tribe_query_debug']) ? $_GET['tribe_query_debug'] : false;
if(($show_debug_info == "true" && $query->is_main_query() === true) || $show_debug_info == "full") {
echo "<h3>&lt;Tribe Events Query&gt;</h3>";
tribe_spit_it_out($query);
add_filter('the_posts', 'tribe_dump_return_query', 100, 1);
}
}
add_action('pre_get_posts', 'tribe_events_pre_get_posts_dumper');
function tribe_dump_return_query($query) {
echo '<p>Query Results:</p>';
tribe_spit_it_out($query);
echo '<p>is_404() = </p>';
var_dump(is_404());
echo '<h3>&lt;/Tribe Events Query&gt;</h3>';
// Only run this once
remove_filter('the_posts', 'tribe_dump_return_query', 100, 1);
return $query;
}
function tribe_spit_it_out($var_for_dumping) {
echo '<pre>';
var_dump($var_for_dumping);
echo '</pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment