2013-08-12 38 views
-2

我已經創建了一個簡單的頁面模板。我想使用wp_insert_category自動創建類別,但wp_insert_category在「我的自定義頁面」中不可用。任何解決方案爲什麼wp_insert_category在我的自定義頁面中不可用?

<?php 
/* 
* Template Name: My Custom Page 
* Description: A Page Template with a darker design. 
*/ 

get_header(); ?> 

<?php 
if (function_exists('wp_insert_category')) { 
    echo "This function is available."; 
} else { 
    echo "This function is not available."; 
} 
?> 

<?php get_footer(); ?> 
+0

在你的頁面中包含'wp_insert_category'是解決方案。 –

回答

2

wp_insert_category是管理員功能。您必須首先包含分類文件。 將以下代碼粘貼到您的functions.php中。那麼只有wp_insert_category函數才能工作。

if (file_exists (ABSPATH.'/wp-admin/includes/taxonomy.php')) { 
     require_once (ABSPATH.'/wp-admin/includes/taxonomy.php'); 
} 
+0

我不介意你是否會投票答覆這個答案。 ;) –

相關問題