Advertisements

wp_edit_posts_query

Definition:
function wp_edit_posts_query( $q = false ) {}

Run the wp query to fetch the posts for listing on the edit posts page

Parameters

  • array|bool $q: Array of query variables to use to build the query or false to use $_GET superglobal.

Defined filters

  • $per_page
    apply_filters( $per_page, $posts_per_page )
  • edit_posts_per_page
    apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type )

Source code

function wp_edit_posts_query( $q = false ) {

	if ( false === $q )

		$q = $_GET;

	$q['m'] = isset($q['m']) ? (int) $q['m'] : 0;

	$q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;

	$post_stati  = get_post_stati();



	if ( isset($q['post_type']) && in_array( $q['post_type'], get_post_types() ) )

		$post_type = $q['post_type'];

	else

		$post_type = 'post';



	$avail_post_stati = get_available_post_statuses($post_type);



	if ( isset($q['post_status']) && in_array( $q['post_status'], $post_stati ) ) {

		$post_status = $q['post_status'];

		$perm = 'readable';

	}



	if ( isset($q['orderby']) )

		$orderby = $q['orderby'];

	elseif ( isset($q['post_status']) && in_array($q['post_status'], array('pending', 'draft')) )

		$orderby = 'modified';



	if ( isset($q['order']) )

		$order = $q['order'];

	elseif ( isset($q['post_status']) && 'pending' == $q['post_status'] )

		$order = 'ASC';



	$per_page = 'edit_' . $post_type . '_per_page';

	$posts_per_page = (int) get_user_option( $per_page );

	if ( empty( $posts_per_page ) || $posts_per_page < 1 )

		$posts_per_page = 20;



	$posts_per_page = apply_filters( $per_page, $posts_per_page );

	$posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type );



	$query = compact('post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page');



	// Hierarchical types require special args.

	if ( is_post_type_hierarchical( $post_type ) && !isset($orderby) ) {

		$query['orderby'] = 'menu_order title';

		$query['order'] = 'asc';

		$query['posts_per_page'] = -1;

		$query['posts_per_archive_page'] = -1;

	}



	if ( ! empty( $q['show_sticky'] ) )

		$query['post__in'] = (array) get_option( 'sticky_posts' );



	wp( $query );



	return $avail_post_stati;

}

3623

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: