• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

「関数リファレンス/get children」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
(en:Function Reference/get children 08:41, 28 December 2009 GeertDD)
(相違点なし)

2010年4月26日 (月) 22:15時点における版

get_children() retrieves attachments, revisions, or sub-Pages, possibly by post parent. It works similarly to get_posts().

Synopsis

array|false $children =& get_children( mixed $args = "", constant $output = OBJECT);

Return values

Returns an associative array of posts (of variable type set by $output parameter) with post IDs as array keys, or false if no posts are found.

As of Version 2.9 the return value will be an empty array instead of false when no children found.

Examples

If you just want to get or display attachments, it's probably a little easier to use get_posts() instead.

$images =& get_children( 'post_type=attachment&post_mime_type=image' );

$videos =& get_children( 'post_type=attachment&post_mime_type=video/mp4' );

if ( empty($images) ) {
	// no attachments here
} else {
	foreach ( $images as $attachment_id => $attachment ) {
		echo wp_get_attachment_image( $attachment_id, 'full' );
	}
}

//  If you don't need to handle an empty result:

foreach ( (array) $videos as $attachment_id => $attachment ) {
	echo wp_get_attachment_link( $attachment_id );
}

Default parameters (Version 2.7)

$defaults = array( 
    'post_parent' => 0,
    'post_type'   => 'any', 
    'numberposts' => -1,
    'post_status' => 'any',
);

Parameters

See get_posts() for a full list of parameters.

As of Version 2.6, you must pass a non-empty post_type parameter (either attachment or page).

$args
(mixed) Passing a query-style string or array sets several parameters (below). Passing an integer post ID or a post object will retrieve children of that post; passing an empty value will retrieve children of the current post or Page.
$args['numberposts']
(integer) Number of child posts to retrieve. Optional; default: -1 (unlimited)
$args['post_parent']
(integer) Pass the ID of a post or Page to get its children. Pass null to get any child regardless of parent. Optional; default: 0 (any parent?)
$args['post_type']
(string) Any value from post_type column of the posts table, such as attachment, page, or revision; or the keyword any. Default: any
$args['post_status']
(string) Any value from the post_status column of the wp_posts table, such as publish, draft, or inherit; or the keyword any. Default: any
$args['post_mime_type']
(string) A full or partial mime-type, e.g. image, video, video/mp4, which is matched against a post's post_mime_type field
$output
(constant) Variable type of the array items returned by the function: one of OBJECT, ARRAY_A, ARRAY_N. Optional; default: OBJECT

Related

get_children() calls get_posts(), which calls $WP_Query->get_posts().

wp_get_attachment_link()


関数リファレンステンプレートタグ目次もご覧ください。

最新英語版: WordPress Codex » Function Reference/get children最新版との差分