get_category_by_path

Sponsored Link

カテゴリースラッグを含んでいるURLに基づいてカテゴリーを取得します。

Sponsored Link

Retrieve category based on URL containing the category slug.

カテゴリスラッグを取得するために$category_pathパラメータを分割します。

Breaks the $category_path parameter up to get the category slug.

子のパスを見つけようとしてそれを返します。一致が見つからない場合は最初のカテゴリーのマッチしているスラッグを返します。$full_matchの場合は、falseに設定されています。もしそれがない場合は、nullを返します。

Tries to find the child path and will return it. If it doesn’t find a match, then it will return the first category matching slug, if $full_match, is set to false. If it does not, then it will return null.

失敗した場合にWP_Errorオブジェクトを返すことも可能です。この機能を使用する場合、それをチェックします。

It is also possible that it will return a WP_Error object on failure. Check for it when using this function.

get_category_by_pathのファンクションタグ使用方法

<?php get_category_by_path( $category_path, $full_match, $output ) ?>

get_category_by_pathのパラメーター

$category_path

(string) (required)カテゴリースラッグを含んでいるURLです。
デフォルト:なし

(string) (required) URL containing category slugs.
Default: None

$full_match

(boolean) (optional)フルパスであるかないかを一致する必要があります。
デフォルト:true

(boolean) (optional) Whether should match full path or not.
Default: true

$output

(string) (optional)OBJECT, ARRAY_A, あるいは ARRAY_Nの定数
デフォルト: OBJECT

(string) (optional) Constant OBJECT, ARRAY_A, or ARRAY_N
Default: OBJECT

戻り値

(null|object|array) 失敗するとNULL。型は$outputの値に基づいています。

(null|object|array)
Null on failure. Type is based on $output value.

デフォルトの使用方法

<?php
$categ = get_category_by_path('uncategorized');
echo "Category ".$categ->name;
?>

注意

変更ログ

Since: 2.1.0

ソースファイル

get_category_by_path()は、wp-includes/category.php内に位置しています。

get_category_by_path() is located in wp-includes/category.php.

Sponsored Link