返回介绍

wp_filter_object_list()

发布于 2017-09-11 11:57:05 字数 3360 浏览 1078 评论 0 收藏 0

wp_filter_object_list( array $list,  array $args = array(),  string $operator = 'and',  bool|string $field = false )

Filters a list of objects, based on a set of key => value arguments.


description


参数

$list

(array) (Required) An array of objects to filter

$args

(array) (Optional) An array of key => value arguments to match against each object.

Default value: array()

$operator

(string) (Optional) The logical operation to perform. 'or' means only one element from the array needs to match; 'and' means all elements must match; 'not' means no elements may match.

Default value: 'and'

$field

(bool|string) (Optional) A field from the object to place instead of the entire object.

Default value: false


返回值

(array) A list of objects or object fields.


源代码

File: wp-includes/functions.php

function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
	if ( ! is_array( $list ) ) {
		return array();
	}

	$util = new WP_List_Util( $list );

	$util->filter( $args, $operator );

	if ( $field ) {
		$util->pluck( $field );
	}

	return $util->get_output();
}

更新日志

Versiondescription
4.7.0Uses WP_List_Util class.
3.0.0Introduced.

相关函数

Uses

  • wp-includes/class-wp-list-util.php: WP_List_Util::__construct()

Used By

  • wp-includes/post.php: get_post_types_by_support()
  • wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::get_columns()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::get_columns()
  • wp-includes/taxonomy.php: get_taxonomies()
  • wp-includes/post.php: get_post_stati()
  • wp-includes/post.php: get_post_types()
  • Show 1 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Filtering out certain post types from the loop following a search

    If multiple post types are returned in a search query you can filter out the posts that are of post type ‘page’ only.

    
    $pages = wp_filter_object_list( $wp_query->posts, array(
    	'post_type' => 'page'
    ) );
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文