Skip to content

Commit

Permalink
カテゴリーキーをmetadata_existsで判別
Browse files Browse the repository at this point in the history
  • Loading branch information
yhira committed Aug 11, 2019
1 parent 3454076 commit d81bdcb
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions lib/content-category.php
Expand Up @@ -26,22 +26,23 @@ function get_the_category_meta($cat_id = null){
}
//カテゴリIDが正常な場合
if ($cat_id) {
$res = get_term_meta( $cat_id, get_the_category_meta_key($cat_id), true );
if (is_array($res)) {
return $res;
} else {
return array();
$key = get_the_category_meta_key($cat_id);
if (term_metadata_exists($cat_id, $key)) {
$res = get_term_meta( $cat_id, $key, true );
if (is_array($res)) {
return $res;
}
}
}
return array();
}
endif;

//カテゴリ色の取得
if ( !function_exists( 'get_the_category_color' ) ):
function get_the_category_color($cat_id = null){
$res = get_term_meta( $cat_id, 'the_category_color', true );
if ($res) {
return $res;
if (term_metadata_exists($cat_id, 'the_category_color')) {
return get_term_meta( $cat_id, 'the_category_color', true );
} else {//旧バージョン対応
$meta = get_the_category_meta($cat_id);
if (!empty($meta['color']))
Expand All @@ -53,9 +54,8 @@ function get_the_category_color($cat_id = null){
//カテゴリ文字色の取得
if ( !function_exists( 'get_the_category_text_color' ) ):
function get_the_category_text_color($cat_id = null){
$res = get_term_meta( $cat_id, 'the_category_text_color', true );
if ($res) {
return $res;
if (term_metadata_exists($cat_id, 'the_category_text_color')) {
return get_term_meta( $cat_id, 'the_category_text_color', true );
} else {//旧バージョン対応
$meta = get_the_category_meta($cat_id);
if (!empty($meta['text_color']))
Expand All @@ -67,9 +67,8 @@ function get_the_category_text_color($cat_id = null){
//カテゴリタイトルの取得
if ( !function_exists( 'get_the_category_title' ) ):
function get_the_category_title($cat_id = null, $is_cat_name = true){
$res = get_term_meta( $cat_id, 'the_category_title', true );
if ($res) {
return $res;
if (term_metadata_exists($cat_id, 'the_category_title')) {
return get_term_meta( $cat_id, 'the_category_title', true );
} else {//旧バージョン対応
$meta = get_the_category_meta($cat_id);
if (!empty($meta['title'])){
Expand All @@ -87,9 +86,8 @@ function get_the_category_title($cat_id = null, $is_cat_name = true){
//カテゴリ本文の取得
if ( !function_exists( 'get_the_category_content' ) ):
function get_the_category_content($cat_id = null){
$res = get_term_meta( $cat_id, 'the_category_content', true );
if ($res) {
return $res;
if (term_metadata_exists($cat_id, 'the_category_content')) {
return get_term_meta( $cat_id, 'the_category_content', true );
} else {//旧バージョン対応
if (!$cat_id) {
$cat_id = get_query_var('cat');
Expand All @@ -111,9 +109,8 @@ function get_the_category_content($cat_id = null){
//アイキャッチの取得
if ( !function_exists( 'get_the_category_eye_catch_url' ) ):
function get_the_category_eye_catch_url($cat_id = null){
$res = get_term_meta( $cat_id, 'the_category_eye_catch_url', true );
if ($res) {
$eye_catch_url = $res;
if (term_metadata_exists($cat_id, 'the_category_eye_catch_url')) {
$eye_catch_url = get_term_meta( $cat_id, 'the_category_eye_catch_url', true );
} else {//旧バージョン対応
$meta = get_the_category_meta($cat_id);
if (!empty($meta['eye_catch'])){
Expand All @@ -135,9 +132,8 @@ function get_the_category_eye_catch_url($cat_id = null){
//カテゴリのメタディスクリプション
if ( !function_exists( 'get_the_category_meta_description' ) ):
function get_the_category_meta_description($cat_id = null){
$res = get_term_meta( $cat_id, 'the_category_meta_description', true );
if ($res) {
return $res;
if (term_metadata_exists($cat_id, 'the_category_meta_description')) {
return get_term_meta( $cat_id, 'the_category_meta_description', true );
} else {//旧バージョン対応
$meta = get_the_category_meta($cat_id);
if (!empty($meta['description']))
Expand Down Expand Up @@ -173,9 +169,8 @@ function get_the_category_snippet($cat_id){
//キーワードの取得
if ( !function_exists( 'get_the_category_meta_keywords' ) ):
function get_the_category_meta_keywords($cat_id = null){
$res = get_term_meta( $cat_id, 'the_category_meta_keywords', true );
if ($res) {
return $res;
if (term_metadata_exists($cat_id, 'the_category_meta_keywords')) {
return get_term_meta( $cat_id, 'the_category_meta_keywords', true );
} else {//旧バージョン対応
$meta = get_the_category_meta($cat_id);
if (!empty($meta['keywords']))
Expand Down

0 comments on commit d81bdcb

Please sign in to comment.