Created
December 20, 2011 21:09
-
-
Save chrisguitarguy/1503285 to your computer and use it in GitHub Desktop.
An example of how to use the posts_where filter in WordPress: don't allow any top-level parents posts into a query.
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_filter( 'posts_where', 'wpse29897_no_parents', 10, 2 ); | |
function wpse29897_no_parents( $where, $query ) | |
{ | |
if( isset( $query->query_vars['post_type'] ) && 'city' == $query->query_vars['post_type'] ) | |
{ | |
if( '' != $where ) | |
{ | |
$where .= ' AND post_parent != 0'; | |
} | |
else | |
{ | |
$where .= ' post_parent != 0'; | |
} | |
} | |
return $where; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment