Created
May 8, 2013 22:26
-
-
Save mrwweb/5544153 to your computer and use it in GitHub Desktop.
Extend WP_Query with reusable arguments. Specify others as needed. (credit due: http://advent.squareonemd.co.uk/neatly-wrapping-custom-post-type-queries-in-a-custom-class-that-extends-wp_query/ & http://bradt.ca/blog/extending-wp_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 | |
// Resuable instance of WP_Query with preset $args | |
class Extended_WP_Query extends WP_Query { | |
function __construct( $args = array() ) { | |
$args = wp_parse_args( $args, array( | |
// some $args go here for reuse | |
) ); | |
parent::__construct( $args ); | |
} | |
} | |
// Then use this like normal WP_Query | |
// e.g.: | |
// $x = new Extended_WP_Query( $args ); while ( $x->have_posts() ) : etc... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment