_post_format_get_terms

函式
_post_format_get_terms ( $terms, $taxonomies, $args )
Access
Private
引數
  • (array) $terms
    Required:
  • (string|array) $taxonomies
    Required:
  • (array) $args
    Required:
返回值
  • (array)
定義位置
相關方法
_post_format_get_term_post_format_wp_get_object_termspost_format_meta_box_post_format_request_post_format_link
引入
3.1.0
棄用
-

_post_format_get_terms: 這個函式用於獲取特定文章格式的所有術語。它需要一個引數,$format,即文章格式的名稱: 當你想獲得與特定文章格式相關的所有術語時,通常使用這個函式。

從get_terms()建立的術語物件的name屬性中刪除post格式字首。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _post_format_get_terms( $terms, $taxonomies, $args ) {
if ( in_array( 'post_format', (array) $taxonomies, true ) ) {
if ( isset( $args['fields'] ) && 'names' === $args['fields'] ) {
foreach ( $terms as $order => $name ) {
$terms[ $order ] = get_post_format_string( str_replace( 'post-format-', '', $name ) );
}
} else {
foreach ( (array) $terms as $order => $term ) {
if ( isset( $term->taxonomy ) && 'post_format' === $term->taxonomy ) {
$terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
}
}
}
}
return $terms;
}
function _post_format_get_terms( $terms, $taxonomies, $args ) { if ( in_array( 'post_format', (array) $taxonomies, true ) ) { if ( isset( $args['fields'] ) && 'names' === $args['fields'] ) { foreach ( $terms as $order => $name ) { $terms[ $order ] = get_post_format_string( str_replace( 'post-format-', '', $name ) ); } } else { foreach ( (array) $terms as $order => $term ) { if ( isset( $term->taxonomy ) && 'post_format' === $term->taxonomy ) { $terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); } } } } return $terms; }
function _post_format_get_terms( $terms, $taxonomies, $args ) {
	if ( in_array( 'post_format', (array) $taxonomies, true ) ) {
		if ( isset( $args['fields'] ) && 'names' === $args['fields'] ) {
			foreach ( $terms as $order => $name ) {
				$terms[ $order ] = get_post_format_string( str_replace( 'post-format-', '', $name ) );
			}
		} else {
			foreach ( (array) $terms as $order => $term ) {
				if ( isset( $term->taxonomy ) && 'post_format' === $term->taxonomy ) {
					$terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
				}
			}
		}
	}
	return $terms;
}

常見問題

FAQs
檢視更多 >