Created
March 1, 2017 18:11
-
-
Save kellenmace/a724475974038aaf1143239da27ee4eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Custom queries and getters. | |
* | |
* @package WDS8 | |
*/ | |
/** | |
* Get two most recent posts. | |
* | |
* @since 8.0.0 | |
* @author Kellen Mace | |
* @return WP_Query The recent posts. | |
*/ | |
function wds_eight_get_two_most_recent_posts() { | |
return new WP_Query( array( | |
'post_type' => 'post', | |
'posts_per_page' => 2, | |
'no_found_rows' => true, | |
'update_post_meta_cache' => false, | |
'update_post_term_cache' => false, | |
) ); | |
} | |
/** | |
* Get the two most recent posts by a specific author. | |
* | |
* @since 8.0.0 | |
* @author Kellen Mace | |
* @param int|string $author_id The user ID of the author whose posts to get. | |
* @return WP_Query The author's posts query results. | |
*/ | |
function wds_eight_get_author_recent_posts( $author_id ) { | |
return new WP_Query( array( | |
'author' => absint( $author_id ), | |
'posts_per_page' => 2, | |
'no_found_rows' => true, | |
'update_post_meta_cache' => false, | |
'update_post_term_cache' => false, | |
) ); | |
} | |
/** | |
* Fetch all portfolio posts. | |
* | |
* @since 8.0.0 | |
* @author Shannon MacMillan | |
* @param array $args Arguments for the query: post count and post type. | |
* @return object $data The WP_Query. | |
*/ | |
function wds_eight_query_portfolio_posts( $args = array() ) { | |
// Setup defaults. | |
$defaults = array( | |
'posts_per_page' => 500, | |
'post_type' => 'portfolio', | |
'orderby' => 'menu_order', | |
'no_found_rows' => true, | |
'update_post_meta_cache' => false, | |
'update_post_term_cache' => false, | |
); | |
// Parse args. | |
$args = wp_parse_args( $args, $defaults ); | |
// Run query. | |
return new WP_Query( $args ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment