get_tags

函式
get_tags ( $args = '' )
引數
  • (string|array) $args { Optional. Arguments to retrieve tags. See get_terms() for additional options. @type string $taxonomy Taxonomy to retrieve terms for. Default 'post_tag'. }
    Required:
    Default: (empty)
返回值
  • (WP_Term[]|int|WP_Error) Array of 'post_tag' term objects, a count thereof, or WP_Error if any of the taxonomies do not exist.
定義位置
相關方法
get_tagget_pagesget_the_tagsget_pagethe_tags
引入
2.3.0
棄用
-

get_tags: 這個函式檢索網站的所有標籤物件的陣列。它不接受任何引數,返回一個標籤物件的陣列。

檢索所有文章的標籤。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_tags( $args = '' ) {
$defaults = array( 'taxonomy' => 'post_tag' );
$args = wp_parse_args( $args, $defaults );
$tags = get_terms( $args );
if ( empty( $tags ) ) {
$tags = array();
} else {
/**
* Filters the array of term objects returned for the 'post_tag' taxonomy.
*
* @since 2.3.0
*
* @param WP_Term[]|int|WP_Error $tags Array of 'post_tag' term objects, a count thereof,
* or WP_Error if any of the taxonomies do not exist.
* @param array $args An array of arguments. @see get_terms()
*/
$tags = apply_filters( 'get_tags', $tags, $args );
}
return $tags;
}
function get_tags( $args = '' ) { $defaults = array( 'taxonomy' => 'post_tag' ); $args = wp_parse_args( $args, $defaults ); $tags = get_terms( $args ); if ( empty( $tags ) ) { $tags = array(); } else { /** * Filters the array of term objects returned for the 'post_tag' taxonomy. * * @since 2.3.0 * * @param WP_Term[]|int|WP_Error $tags Array of 'post_tag' term objects, a count thereof, * or WP_Error if any of the taxonomies do not exist. * @param array $args An array of arguments. @see get_terms() */ $tags = apply_filters( 'get_tags', $tags, $args ); } return $tags; }
function get_tags( $args = '' ) {
	$defaults = array( 'taxonomy' => 'post_tag' );
	$args     = wp_parse_args( $args, $defaults );

	$tags = get_terms( $args );

	if ( empty( $tags ) ) {
		$tags = array();
	} else {
		/**
		 * Filters the array of term objects returned for the 'post_tag' taxonomy.
		 *
		 * @since 2.3.0
		 *
		 * @param WP_Term[]|int|WP_Error $tags Array of 'post_tag' term objects, a count thereof,
		 *                                     or WP_Error if any of the taxonomies do not exist.
		 * @param array                  $args An array of arguments. @see get_terms()
		 */
		$tags = apply_filters( 'get_tags', $tags, $args );
	}

	return $tags;
}

常見問題

FAQs
檢視更多 >