PUM_Helpers::post_type_selectlist_query( $post_type, $args = array(), $include_total = false )
Description Description
Source Source
File: classes/Helpers.php
public static function post_type_selectlist_query( $post_type, $args = array(), $include_total = false ) { $args = wp_parse_args( $args, array( 'posts_per_page' => 10, 'post_type' => $post_type, 'post__in' => null, 'post__not_in' => null, 'post_status' => null, 'page' => 1, // Performance Optimization. 'no_found_rows' => ! $include_total ? true : false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, ) ); if ( $post_type == 'attachment' ) { $args['post_status'] = 'inherit'; } // Query Caching. static $queries = array(); $key = md5( serialize( $args ) ); if ( ! isset( $queries[ $key ] ) ) { $query = new WP_Query( $args ); $posts = array(); foreach ( $query->posts as $post ) { $posts[ $post->ID ] = $post->post_title; } $results = array( 'items' => $posts, 'total_count' => $query->found_posts, ); $queries[ $key ] = $results; } else { $results = $queries[ $key ]; } return ! $include_total ? $results['items'] : $results; }
Expand full source code Collapse full source code View on Trac