Last active
December 11, 2015 05:19
-
-
Save tomjn/4551786 to your computer and use it in GitHub Desktop.
hmmm initialise in the loop start, loop_end shouldn't ever be called without loop_start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'loop_start', 'qd_loop_start' ); | |
add_action( 'loop_end', 'qd_loop_end' ); | |
function qd_loop_start( $query ) { | |
global $query_depth; | |
if(!isset($query_depth)){ | |
$query_depth = 0; | |
} | |
$query_depth++; | |
} | |
function qd_loop_end( $query ) { | |
global $query_depth; | |
$query_depth--; | |
} | |
function get_query_depth(){ | |
global $query_depth; | |
if(!isset($query_depth)){ | |
$query_depth = 0; | |
} | |
return $query_depth; | |
} | |
function my_in_main_loop() { | |
$result = ( get_query_depth() == 1) && ( is_main_query() ) ); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note to self, needs another bit of code to initialize $query_depth other than get_query_depth itself