本文整理汇总了PHP中wp_create_category函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_create_category函数的具体用法?PHP wp_create_category怎么用?PHP wp_create_category使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_create_category函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: elaplugin_activate
function elaplugin_activate()
{
$terms_to_add = array("European Language Portfolio");
//create those categories if they don't already exist
foreach ($terms_to_add as $trm) {
if (term_exists($trm) == 0) {
wp_create_category($trm);
}
}
}
开发者ID:bacalj,项目名称:wp-european-language-assessment,代码行数:10,代码来源:elaplugin.php
示例2: create_category
public function create_category()
{
require_once ABSPATH . 'wp-admin/includes/taxonomy.php';
if (isset($_POST['addcat'])) {
$newcat = $_POST['newcat'];
if (wp_create_category($newcat)) {
$this->alert = 'New Category Created';
}
}
}
开发者ID:haizrul,项目名称:WP-Mizon,代码行数:10,代码来源:stupidbot.php
示例3: property_detail_content
function property_detail_content($content)
{
if (get_post_meta(get_the_ID(), 'property_id', true) != '' && get_post_meta(get_the_ID(), 'bapi_last_update', true) < time() - 3600 * 60 * 24) {
remove_filter('save_post', 'update_post_bapi');
wp_update_post(mod_post_builder($propid, get_the_ID()));
update_post_meta(get_the_ID(), 'bapi_last_update', time());
wp_set_post_terms(get_the_ID(), wp_create_category(get_option('property_category_name')), 'category');
add_filter('save_post', 'update_post_bapi');
}
bapi_search_page_body($content);
return $content;
}
开发者ID:alfiedawes,项目名称:WP-InstaSites,代码行数:12,代码来源:property.php
示例4: create_categories
private function create_categories($post)
{
$course_category = get_post_meta($post->ID, "course_category_id", true);
if ($course_category == "") {
$course_category = wp_create_category($post->post_title);
add_post_meta($post->ID, "course_category_id", $course_category, true);
}
$discussion_category = get_post_meta($post->ID, "course_discussion", true);
if ($discussion_category == "") {
$discussion_category = wp_create_category(__("discussions"), $course_category);
add_post_meta($post->ID, "course_discussion", $discussion_category, true);
}
return array($course_category, $discussion_category);
}
开发者ID:pgogy,项目名称:WordPress-MOLIE,代码行数:14,代码来源:molie-discussion-ajax.php
示例5: wp_create_categories
/**
* Create categories for the given post.
*
* @since 2.0.0
*
* @param array $categories List of categories to create.
* @param int $post_id Optional. The post ID. Default empty.
* @return List of categories to create for the given post.
*/
function wp_create_categories($categories, $post_id = '')
{
$cat_ids = array();
foreach ($categories as $category) {
if ($id = category_exists($category)) {
$cat_ids[] = $id;
} elseif ($id = wp_create_category($category)) {
$cat_ids[] = $id;
}
}
if ($post_id) {
wp_set_post_categories($post_id, $cat_ids);
}
return $cat_ids;
}
开发者ID:nstungxd,项目名称:F2CA5,代码行数:24,代码来源:taxonomy.php
示例6: create_my_cat
function create_my_cat()
{
if (file_exists(ABSPATH . '/wp-admin/includes/taxonomy.php')) {
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
$loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1));
while ($loop->have_posts()) {
$loop->the_post();
global $post;
$post_slug = $post->post_name;
if (!get_cat_ID($post_slug)) {
wp_create_category($post_slug);
}
}
wp_reset_query();
}
}
开发者ID:nikonikoniko,项目名称:rudiment_homepage,代码行数:16,代码来源:functions.php
示例7: create_categories
private function create_categories($post)
{
$categories = array();
$course_category = get_post_meta($post->ID, "course_category_id", true);
if ($course_category == "") {
$course_category = wp_create_category($post->post_title);
add_post_meta($post->ID, "course_category_id", $course_category, true);
}
array_push($categories, $course_category);
$assignment_category = get_post_meta($post->ID, "course_module_assignments", true);
if ($module_category == "") {
$assignment_category = wp_create_category("Assignments", $course_category);
add_post_meta($post->ID, "course_module_assignments", $assignment_category, true);
}
array_push($categories, $assignment_category);
return $categories;
}
开发者ID:pgogy,项目名称:WordPress-MOLIE,代码行数:17,代码来源:molie-assignment-ajax.php
示例8: create_categories
private function create_categories($post)
{
$categories = array();
$course_category = get_post_meta($post->ID, "course_category_id", true);
if ($course_category == "") {
$course_category = wp_create_category($post->post_title);
add_post_meta($post->ID, "course_category_id", $course_category, true);
}
array_push($categories, $course_category);
$student_category = get_post_meta($post->ID, "course_students", true);
if ($quiz_category == "") {
$student_category = wp_create_category("Students", $course_category);
add_post_meta($post->ID, "course_students", $student_category, true);
}
array_push($categories, $student_category);
return $categories;
}
开发者ID:pgogy,项目名称:WordPress-MOLIE,代码行数:17,代码来源:molie-roster-ajax.php
示例9: activation
/**
* Create the new Genealogy Update category.
* Schedule an update of the TNG RSS feed.
*
* @author Nate Jacobs
* @date 9/11/14
* @since 1.0
*/
public function activation()
{
wp_create_category($this->tng_rss_category);
/**
* Filter the scheduled recurrence event time.
*
* @author Nate Jacobs
* @date 11/1/14
* @since 1.6
*
* @param string The cron interval.
*/
$schedule = apply_filters('tng_wp_rss_post_schedule', 'daily');
if (!wp_next_scheduled('tng_wp_rss_update')) {
wp_schedule_event(time(), $schedule, 'tng_wp_rss_update');
}
}
开发者ID:NateJacobs,项目名称:TNG-RSS-to-WordPress-Post,代码行数:25,代码来源:tng-wp-rss.php
示例10: create_categories
private function create_categories($post)
{
$categories = array();
$course_category = get_post_meta($post->ID, "course_category_id", true);
if ($course_category == "") {
$course_category = wp_create_category($post->post_title);
add_post_meta($post->ID, "course_category_id", $course_category, true);
}
array_push($categories, $course_category);
if (isset($_POST['module'])) {
$module_category = get_post_meta($post->ID, "course_module_" . $_POST['module'], true);
if ($module_category == "") {
$module_category = wp_create_category(stripslashes($_POST['module_name']), $course_category);
add_post_meta($post->ID, "course_module_" . $_POST['module'], $module_category, true);
}
array_push($categories, $module_category);
}
return $categories;
}
开发者ID:pgogy,项目名称:WordPress-MOLIE,代码行数:19,代码来源:molie-choose-ajax.php
示例11: make_category
function make_category($slug, $parent = null)
{
//既存カテゴリをすべて取得
$categories = get_categories($args);
//print_r($categories);
$flag = 0;
foreach ($categories as $cat) {
if ($slug == $cat->name) {
$flag = 1;
$cat_id = $cat->cat_ID;
break;
}
}
if ($flag != 1) {
//重複無ければ
return wp_create_category($slug, $parent);
} else {
return $cat_id;
}
}
开发者ID:bitai,项目名称:wordpress,代码行数:20,代码来源:maker_model_asoc.php
示例12: wpse_set_defaults
function wpse_set_defaults($blog_id)
{
global $json_api;
switch_to_blog($blog_id);
$id = 'json_api_controllers';
$required_controllers = explode(",", "categories,posts,user,projects,attachments");
$available_controllers = $json_api->get_controllers();
$active_controllers = explode(',', get_option($id, 'core'));
$action = "activate";
foreach ($required_controllers as $controller) {
if (in_array($controller, $available_controllers)) {
if ($action == 'activate' && !in_array($controller, $active_controllers)) {
$active_controllers[] = $controller;
} else {
if ($action == 'deactivate') {
$index = array_search($controller, $active_controllers);
if ($index !== false) {
unset($active_controllers[$index]);
}
}
}
}
}
$value = implode(',', $active_controllers);
$option_exists = get_option($id, null) !== null;
if ($option_exists) {
update_option($id, $value);
} else {
add_option($id, $value);
}
// Remove the default post & page
wp_delete_post(1, true);
wp_delete_post(2, true);
// Remove the first comment
wp_delete_comment(1, true);
// add default categories
wp_create_category("Project");
wp_create_category("Document");
restore_current_blog();
}
开发者ID:andreiRS,项目名称:Radii8,代码行数:40,代码来源:api.php
示例13: explode
$mycats = explode(",", $a[0]["mycats"]);
echo "{$appear_pk} <br>";
$tags = "";
if ($a[0]["show_nm2"]) {
$tags .= "," . $a[0]["show_nm2"];
}
if ($a[0]["show_nm3"]) {
$tags .= "," . $a[0]["show_nm3"];
}
/*
// add show to categories if not a category yet
$showcat = wp_create_category($shownm, 161);
if ($showcat) $mycats[] = $showcat;
*/
// add PERSON to categories if not a category yet
$personcat = wp_create_category($peoplenm, $peoplecat);
if ($personcat) {
$mycats[] = $personcat;
}
$title = $peoplenm . " on " . $shownm . " on " . $dt2;
// 'ID' => $postfk,
// Create post object
$my_post = array('post_type' => "appearance", 'post_title' => $title, 'post_content' => "", 'post_status' => 'publish', 'post_author' => 1, 'post_category' => $mycats, 'tags_input' => $shownm . "," . $peoplenm . $tags, 'post_date' => $dt);
print_r($my_post);
$postid = wp_insert_post($my_post);
update_post_meta($postid, '_wp_page_template', 'single-appear.php');
$q = "UPDATE appearances SET appear_post = {$postid} WHERE appear_pk = {$appear_pk}";
$conn->query($q);
echo $q;
echo "<hr>";
// break;
开发者ID:justinwool,项目名称:vortago,代码行数:31,代码来源:test_createAppearancePost.php
示例14: die
die('-1');
}
$names = explode(',', $_POST['newcat']);
if (0 > ($parent = (int) $_POST['newcat_parent'])) {
$parent = 0;
}
$post_category = isset($_POST['post_category']) ? (array) $_POST['post_category'] : array();
$checked_categories = array_map('absint', (array) $post_category);
$popular_ids = wp_popular_terms_checklist('category', 0, 10, false);
foreach ($names as $cat_name) {
$cat_name = trim($cat_name);
$category_nicename = sanitize_title($cat_name);
if ('' === $category_nicename) {
continue;
}
$cat_id = wp_create_category($cat_name, $parent);
$checked_categories[] = $cat_id;
if ($parent) {
// Do these all at once in a second
continue;
}
$category = get_category($cat_id);
ob_start();
wp_category_checklist(0, $cat_id, $checked_categories, $popular_ids);
$data = ob_get_contents();
ob_end_clean();
$add = array('what' => 'category', 'id' => $cat_id, 'data' => str_replace(array("\n", "\t"), '', $data), 'position' => -1);
}
if ($parent) {
// Foncy - replace the parent and all its children
$parent = get_category($parent);
开发者ID:nagyist,项目名称:laura-wordpress,代码行数:31,代码来源:admin-ajax.php
示例15: test_terms_search
function test_terms_search()
{
$this->make_user_by_role('editor');
$name = rand_str(30);
$name_id = wp_create_category($name);
// search by full name
$filter = array('search' => $name);
$results = $this->myxmlrpcserver->wp_getTerms(array(1, 'editor', 'editor', 'category', $filter));
$this->assertNotInstanceOf('IXR_Error', $results);
$this->assertEquals(1, count($results));
$this->assertEquals($name, $results[0]['name']);
$this->assertEquals($name_id, $results[0]['term_id']);
// search by partial name
$filter = array('search' => substr($name, 0, 10));
$results2 = $this->myxmlrpcserver->wp_getTerms(array(1, 'editor', 'editor', 'category', $filter));
$this->assertNotInstanceOf('IXR_Error', $results2);
$this->assertEquals(1, count($results2));
$this->assertEquals($name, $results2[0]['name']);
$this->assertEquals($name_id, $results2[0]['term_id']);
}
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:20,代码来源:getTerms.php
示例16: ConvertCategory
function ConvertCategory($start = false)
{
global $wpdb;
if (!$start) {
$start = 0;
}
$end = 200;
$count_category = $wpdb->get_var("SELECT COUNT(*) FROM `categories` WHERE status > 0");
$categories = $wpdb->get_results("SELECT * FROM `categories` WHERE `status` > 0 ORDER BY `parent` ASC LIMIT {$start} , {$end}", 'ARRAY_A');
foreach ($categories as $category) {
/*
if ( $term_id = category_exists($category['name']) ) {
$wpdb->insert(
'category_to_terms',
array( 'category_id' => $category['id'], 'term_id' => $term_id ),
array( '%d', '%d' )
);
} else {
*/
$parent = $wpdb->get_var("SELECT `term_id` FROM `category_to_terms` WHERE `category_id` = '" . $category['parent'] . "'");
if ($term_id = wp_create_category($category['name'], $parent)) {
$wpdb->insert('category_to_terms', array('category_id' => $category['id'], 'term_id' => $term_id), array('%d', '%d'));
}
// }
}
$count_added_category = $wpdb->get_var("SELECT COUNT(*) FROM `category_to_terms`");
?>
<div class="cc_title"><h2>Category</h2></div>
<script>
var a1 = <?php
echo $count_category;
?>
;
var a2 = <?php
echo $start;
?>
;
jQuery(function(){
if (a2 <= a1) {
url = "?page=CC&action=category&start=<?php
echo $start + $end;
?>
";
jQuery(location).attr("href", url);
} else {
url = "?page=CC&action=post";
jQuery(location).attr("href", url);
}
});
</script>
<div class="cc_content">
<?php
echo '<div>Total categories: ' . ($count_category - 1) . '</div>';
echo '<div><a href="?page=CC&action=category&start=' . ($start + $end) . '">Next categories >>></a></div>';
?>
</div>
<?php
SelestAction();
}
开发者ID:yarylo,项目名称:cerkva.pp.ua,代码行数:63,代码来源:cerkva-convertation.php
示例17: cpm_action_build_storyline_schema
function cpm_action_build_storyline_schema()
{
global $cpm_config;
update_option('comicpress-enable-storyline-support', isset($_POST['enable-storyline-support']) ? 1 : 0);
update_option('comicpress-storyline-show-top-category', isset($_POST['show-top-category']) ? 1 : 0);
if (isset($_POST['enable-storyline-support'])) {
$cpm_config->is_cpm_modifying_categories = true;
$categories_to_create = array();
$categories_to_rename = array();
$category_ids_to_clean = array();
extract(cpm_get_all_comic_categories());
$comic_posts = cpm_query_posts();
$comic_posts_by_category_id = array();
foreach ($comic_posts as $post) {
foreach (wp_get_post_categories($post->ID) as $category) {
if (!isset($comic_posts_by_category_id[$category])) {
$comic_posts_by_category_id[$category] = array();
}
$comic_posts_by_category_id[$category][] = $post->ID;
}
}
foreach ($_POST as $field => $value) {
$value = stripslashes($value);
$parts = explode("/", $field);
if ($parts[0] == "0" && count($parts) > 1) {
$category_id = end($parts);
$category = get_category($category_id);
if (!empty($category)) {
$category = (array) $category;
if ($category['cat_name'] != $value) {
$cpm_config->messages[] = sprintf(__('Category <strong>%1$s</strong> renamed to <strong>%2$s</strong>.', 'comicpress-manager'), $category['cat_name'], $value);
$category['cat_name'] = $value;
wp_update_category($category);
$category_ids_to_clean[] = $category_id;
}
} else {
$categories_to_create[$field] = $value;
}
if (($index = array_search($field, $category_tree)) !== false) {
array_splice($category_tree, $index, 1);
}
}
}
if (isset($_POST['original-categories'])) {
foreach (explode(",", $_POST['original-categories']) as $node) {
if (!isset($_POST[$node])) {
$category_id = end(explode("/", $node));
$category = get_category($category_id);
$original_cat_name = $category->cat_name;
// ensure that we're not deleting a ComicPress category
$ok = true;
foreach (array('comiccat', 'blogcat') as $type) {
if ($category_id == $cpm_config->properties[$type]) {
$ok = false;
}
}
// ensure that the category truly is a child of the comic category
if ($ok) {
$category = get_category($category_id);
$ok = false;
if (!is_wp_error($category)) {
while ($category->parent != 0 && $category->parent != $cpm_config->properties['comiccat']) {
$category = get_category($category->parent);
}
if ($category->parent == $cpm_config->properties['comiccat']) {
$ok = true;
}
}
}
if ($ok) {
wp_delete_category($category_id);
$category_ids_to_clean[] = $category_id;
$cpm_config->messages[] = sprintf(__('Category <strong>%s</strong> deleted.', 'comicpress-manager'), $original_cat_name);
}
}
}
}
uksort($categories_to_create, 'cpm_sort_category_keys_by_length');
$changed_field_ids = array();
$removed_field_ids = array();
$target_category_ids = array();
foreach ($categories_to_create as $field => $value) {
$original_field = $field;
foreach ($changed_field_ids as $changed_field => $new_field) {
if (strpos($field, $changed_field) === 0 && strlen($field) > strlen($changed_field)) {
$field = str_replace($changed_field, $new_field, $field);
break;
}
}
$parts = explode("/", $field);
$target_id = array_pop($parts);
$parent_id = array_pop($parts);
if (!category_exists($value)) {
$category_id = wp_create_category($value, $parent_id);
$category_ids_to_clean[] = $category_id;
array_push($parts, $parent_id);
array_push($parts, $category_id);
$changed_field_ids[$original_field] = implode("/", $parts);
$cpm_config->messages[] = sprintf(__('Category <strong>%s</strong> created.', 'comicpress-manager'), $value);
} else {
//.........这里部分代码省略.........
开发者ID:johnbintz,项目名称:comicpress-manager-1.4,代码行数:101,代码来源:comicpress_build-storyline-schema.php
示例18: explode
if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) )
die('1');
}
die('0');
break;
case 'add-category' : // On the Fly
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$names = explode(',', $_POST['newcat']);
$x = new WP_Ajax_Response();
foreach ( $names as $cat_name ) {
$cat_name = trim($cat_name);
if ( !$category_nicename = sanitize_title($cat_name) )
die('0');
if ( !$cat_id = category_exists( $cat_name ) )
$cat_id = wp_create_category( $cat_name );
$cat_name = wp_specialchars(stripslashes($cat_name));
$x->add( array(
'what' => 'category',
'id' => $cat_id,
'data' => "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>"
) );
}
$x->send();
break;
case 'add-cat' : // From Manage->Categories
if ( !current_user_can( 'manage_categories' ) )
die('-1');
if ( !$cat = wp_insert_category( $_POST ) )
die('0');
if ( !$cat = get_category( $cat ) )
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:31,代码来源:admin-ajax.php
示例19: process_feed
//.........这里部分代码省略.........
}
} else {
// Use a different author
$author = $ablog['author'];
}
// Set up the category
if ((int) $ablog['category'] >= 0) {
// Grab the first main category
$cats = array((int) $ablog['category']);
} else {
$cats = array();
}
$post_category = $cats;
// Set up the tags
$tags = array();
if (!empty($ablog['tag'])) {
$tags = array_map('trim', explode(',', $ablog['tag']));
}
switch ($ablog['feedcatsare']) {
case 'categories':
//$term = get_term_by('name', $cat_name, 'category');
$thecats = array();
$thecats = $item->get_categories();
if (!empty($thecats)) {
foreach ($thecats as $category) {
$cat_name = trim($category->get_label());
$term_id = $this->category_exists($cat_name);
if (!empty($term_id)) {
$post_category[] = $term_id;
} else {
// need to check and add cat if required
if ($ablog['originalcategories'] == '1') {
// yes so add
$term_id = wp_create_category($cat_name);
if (!empty($term_id)) {
$post_category[] = $term_id;
}
}
}
}
}
break;
case 'tags':
// carry on as default as well
// carry on as default as well
default:
$thecats = array();
if (isset($ablog['originalcategories']) && $ablog['originalcategories'] == '1') {
$thecats = $item->get_categories();
if (!empty($thecats)) {
foreach ($thecats as $category) {
$tags[] = trim($category->get_label());
}
}
}
break;
}
$tax_input = array("post_tag" => $tags);
$post_status = $ablog['poststatus'];
$post_type = $ablog['posttype'];
if ($ablog['postdate'] != 'existing') {
$post_date = current_time('mysql');
$post_date_gmt = current_time('mysql', 1);
} else {
$thedate = $item->get_date();
$post_date = date('Y-m-d H:i:s', strtotime($thedate));
开发者ID:hscale,项目名称:webento,代码行数:67,代码来源:autoblogprocess.php
示例20: add_category
function add_category($param_new_category)
{
$new_categ_name = $parent_of = $categ_slug = '';
$new_categ_name = trim($param_new_category[0]);
$parent_of = intval($param_new_category[1]);
if (!empty($new_categ_name)) {
wp_create_category($new_categ_name, $parent_of);
}
//create slag from category name,
$category_slug = str_replace(' ', '-', strtolower($new_categ_name));
//get category id //alse can be used get_cat_ID( $cat_name )
$this->category_array[] = get_category_by_slug($category_slug)->cat_ID;
$this->log("create_category({$param_new_category['0']})", '');
}
开发者ID:Vatia13,项目名称:wordpress,代码行数:14,代码来源:td_demo_site.php
注:本文中的wp_create_category函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论