• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_set_post_categories函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_set_post_categories函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_set_post_categories函数的具体用法?PHP wp_set_post_categories怎么用?PHP wp_set_post_categories使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_set_post_categories函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: _rs_mt_set_categories

function _rs_mt_set_categories($args)
{
    global $wp_xmlrpc_server;
    $wp_xmlrpc_server->escape($args);
    $post_ID = (int) $args[0];
    $username = $args[1];
    $password = $args[2];
    $categories = $args[3];
    if (!($user = $wp_xmlrpc_server->login($username, $password))) {
        return $wp_xmlrpc_server->error;
    }
    if (empty($categories)) {
        $categories = array();
    }
    $catids = array();
    foreach ($categories as $cat) {
        $catids[] = $cat['categoryId'];
    }
    $catids = apply_filters('pre_object_terms_rs', $catids, 'category');
    do_action('xmlrpc_call', 'mt.setPostCategories');
    if (!get_post($post_ID)) {
        return new IXR_Error(404, __('Invalid post ID.'));
    }
    if (!current_user_can('edit_post', $post_ID)) {
        return new IXR_Error(401, __('Sorry, you cannot edit this post.'));
    }
    wp_set_post_categories($post_ID, $catids);
    return true;
}
开发者ID:joostrijneveld,项目名称:cscircles-wp-content,代码行数:29,代码来源:xmlrpc_rs.php


示例2: save_default_post_categories

 /**
  * This function set post in default category.
  *
  * @param $post_ID
  *
  * @return mixed
  */
 public function save_default_post_categories($post_ID)
 {
     if (wp_is_post_autosave($post_ID) || wp_is_post_revision($post_ID)) {
         return $post_ID;
     }
     $categories = wp_get_post_categories($post_ID);
     if (count($categories) === 1 && $categories[0] === (int) get_option('default_category')) {
         $cats = (array) $this->get_default_post_category_by_lang(get_post_meta($post_ID, 'translation_lang', true));
         wp_set_post_categories($post_ID, $cats);
     }
 }
开发者ID:albertso,项目名称:Unyson-Translation-Extension,代码行数:18,代码来源:class-fw-extension-translate-terms.php


示例3: testSetupMulticomicPartialPaths

 function testSetupMulticomicPartialPaths()
 {
     $cp = $this->getMock('ComicPress', array('_is_dir'));
     wp_set_post_categories(1, array('2', '3'));
     add_category('2', (object) array('slug' => 'test-one'));
     add_category('3', (object) array('slug' => 'test-two'));
     $cp->expects($this->at(0))->method('_is_dir')->with('/subthemes/test-one')->will($this->returnValue(true));
     $cp->expects($this->at(1))->method('_is_dir')->with('/subthemes/test-two')->will($this->returnValue(false));
     $cp->setup_multicomic_partial_paths(1);
     $this->assertEquals(array('/subthemes/test-one'), $cp->partial_paths);
 }
开发者ID:johnbintz,项目名称:comicpress-theme-core,代码行数:11,代码来源:ComicPressTest.php


示例4: test_dotted_formats

 /**
  * @ticket 21167
  */
 public function test_dotted_formats()
 {
     global $wp_rewrite;
     // Create a sample post
     $cat_id = $this->factory->term->create(array('name' => 'permalink-test', 'taxonomy' => 'category'));
     $user_id = $this->factory->user->create(array('role' => 'editor', 'user_login' => 'permalink_user'));
     $post_id = $this->factory->post->create(array('post_title' => 'lorem-ipsum', 'post_date' => '2012-08-02 14:15:05', 'post_author' => $user_id, 'category' => $cat_id));
     wp_set_post_categories($post_id, array($cat_id));
     // Sample permalinks
     $tests = array('/%postname%.%post_id%/ ' => array('regex' => '([^/]+)\\.([0-9]+)(/[0-9]+)?/?$', 'url' => 'index.php?name=$1&p=$2&page=$3'), '/%year%.%monthnum%.%postname%/' => array('regex' => '([0-9]{4})\\.([0-9]{1,2})\\.([^/]+)(/[0-9]+)?/?$', 'url' => 'index.php?year=$1&monthnum=$2&name=$3&page=$4'), '/%post_id%.%postname%/' => array('regex' => '([0-9]+)\\.([^/]+)(/[0-9]+)?/?$', 'url' => 'index.php?p=$1&name=$2&page=$3'), '/%postname%.%year%/' => array('regex' => '([^/]+)\\.([0-9]{4})(/[0-9]+)?/?$', 'url' => 'index.php?name=$1&year=$2&page=$3'), '/$%postname%$/' => array('regex' => '\\$([^/]+)\\$(/[0-9]+)?/?$', 'url' => 'index.php?name=$1&page=$2'), '%year%.+?%monthnum%.+?%day%.+?%hour%.+?%minute%.+?%second%.+?%post_id%.+?%postname%.+?%category%.+?%author%.+?' => array('regex' => '([0-9]{4})\\.\\+\\?([0-9]{1,2})\\.\\+\\?([0-9]{1,2})\\.\\+\\?([0-9]{1,2})\\.\\+\\?([0-9]{1,2})\\.\\+\\?([0-9]{1,2})\\.\\+\\?([0-9]+)\\.\\+\\?([^/]+)\\.\\+\\?%category%\\.\\+\\?([^/]+)\\.\\+\\?(/[0-9]+)?/?$', 'url' => 'index.php?year=$1&monthnum=$2&day=$3&hour=$4&minute=$5&second=$6&p=$7&name=$8&%category%$9&author_name=$10&page=$11'));
     // Test permalinks
     foreach ($tests as $permalink_format => $expected) {
         update_option('permalink_structure', $permalink_format);
         // Get the rewrite rules
         $rules = $wp_rewrite->generate_rewrite_rules(get_option('permalink_structure'), EP_PERMALINK, false, false, false, false);
         // Filter out only the post rewrite rule
         foreach ($rules as $regex => $url) {
             if (false === strpos($url, 'attachment=$') && false === strpos($url, 'tb=') && false === strpos($url, 'cpage=$')) {
                 break;
             }
         }
         // Test that expected === actual
         $this->assertEquals($regex, $expected['regex'], "Problem with permalink format: {$permalink_format}");
         $this->assertEquals($url, $expected['url'], "Problem with permalink format: {$permalink_format}");
     }
 }
开发者ID:boonebgorges,项目名称:wp,代码行数:29,代码来源:permalinkFormats.php


示例5: test_category__and_var

	function test_category__and_var() {
		$term_id = $this->factory->category->create( array( 'slug' => 'woo', 'name' => 'WOO!' ) );
		$term_id2 = $this->factory->category->create( array( 'slug' => 'hoo', 'name' => 'HOO!' ) );
		$post_id = $this->factory->post->create();

		wp_set_post_categories( $post_id, $term_id );

		$posts = $this->q->query( array( 'category__and' => array( $term_id ) ) );

		$this->assertEmpty( $this->q->get( 'category__and' ) );
		$this->assertCount( 0, $this->q->get( 'category__and' ) );
		$this->assertNotEmpty( $this->q->get( 'category__in' ) );
		$this->assertCount( 1, $this->q->get( 'category__in' ) );

		$this->assertNotEmpty( $posts );
		$this->assertEquals( array( $post_id ), wp_list_pluck( $posts, 'ID' ) );

		$posts2 = $this->q->query( array( 'category__and' => array( $term_id, $term_id2 ) ) );
		$this->assertNotEmpty( $this->q->get( 'category__and' ) );
		$this->assertCount( 2, $this->q->get( 'category__and' ) );
		$this->assertEmpty( $this->q->get( 'category__in' ) );
		$this->assertCount( 0, $this->q->get( 'category__in' ) );

		$this->assertEmpty( $posts2 );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:25,代码来源:query.php


示例6: testGetValidPostCategory

 /**
  * @dataProvider providerTestGetValidPostCategory
  */
 function testGetValidPostCategory($post_categories, $expected_result)
 {
     $css = $this->getMock('ComicPressStoryline', array('valid'));
     $css->expects($this->any())->method('valid')->will($this->returnValue(true));
     wp_set_post_categories(1, $post_categories);
     $this->assertEquals($expected_result, $css->get_valid_post_category(1));
 }
开发者ID:johnbintz,项目名称:comicpress-theme-core,代码行数:10,代码来源:ComicPressStorylineTest.php


示例7: set_post_categories

 /**
  * Update the post categories based on all post category fields
  *
  * @since 1.17
  *
  * @param array $form Gravity Forms form array
  * @param int $entry_id Numeric ID of the entry that was updated
  *
  * @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure. false if there are no post category fields or connected post.
  */
 public function set_post_categories($form = array(), $entry_id = 0)
 {
     $entry = GFAPI::get_entry($entry_id);
     $post_id = rgar($entry, 'post_id');
     if (empty($post_id)) {
         return false;
     }
     $return = false;
     $post_category_fields = GFAPI::get_fields_by_type($form, 'post_category');
     if ($post_category_fields) {
         $updated_categories = array();
         foreach ($post_category_fields as $field) {
             // Get the value of the field, including $_POSTed value
             $field_cats = RGFormsModel::get_field_value($field);
             $field_cats = is_array($field_cats) ? array_values($field_cats) : (array) $field_cats;
             $field_cats = gv_map_deep($field_cats, 'intval');
             $updated_categories = array_merge($updated_categories, array_values($field_cats));
         }
         // Remove `0` values from intval()
         $updated_categories = array_filter($updated_categories);
         /**
          * @filter `gravityview/edit_entry/post_categories/append` Should post categories be added to or replaced?
          * @since 1.17
          * @param bool $append If `true`, don't delete existing categories, just add on. If `false`, replace the categories with the submitted categories. Default: `false`
          */
         $append = apply_filters('gravityview/edit_entry/post_categories/append', false);
         $return = wp_set_post_categories($post_id, $updated_categories, $append);
     }
     return $return;
 }
开发者ID:mgratch,项目名称:GravityView,代码行数:40,代码来源:class-gravityview-field-post-category.php


示例8: ajax_new

 function ajax_new()
 {
     check_ajax_referer('fee-new', 'nonce');
     require_once ABSPATH . '/wp-admin/includes/post.php';
     $post = get_default_post_to_edit(isset($_POST['post_type']) ? $_POST['post_type'] : 'post', true);
     wp_set_post_categories($post->ID, array(get_option('default_category')));
     wp_send_json_success(get_permalink($post->ID));
 }
开发者ID:louis-ev,项目名称:wp-front-end-editor,代码行数:8,代码来源:class-fee.php


示例9: testFindParents

 /**
  * @dataProvider providerTestFindParents
  */
 function testFindParents($post_categories, $expected_result)
 {
     add_category(1, (object) array('slug' => 'root', 'parent' => 0));
     add_category(2, (object) array('slug' => 'comic', 'parent' => 1));
     add_category(3, (object) array('slug' => 'part-1', 'parent' => 2));
     add_category(4, (object) array('slug' => 'blog', 'parent' => 1));
     wp_set_post_categories(1, $post_categories);
     $this->p->post = (object) array('ID' => 1);
     $this->assertEquals($expected_result, $this->p->find_parents());
 }
开发者ID:johnbintz,项目名称:comicpress-core,代码行数:13,代码来源:ComicPressComicPostTest.php


示例10: ahny_update_post_terms

function ahny_update_post_terms($post_id)
{
    $post = get_post($post_id);
    if ('post' === $post->post_type) {
        $categories = wp_get_post_categories($post_id);
        $newcat = get_term_by('name', 'Living Modern', 'category');
        array_push($categories, $newcat->term_id);
        wp_set_post_categories($post_id, $categories);
    }
}
开发者ID:amaschas,项目名称:architecturalhomesny,代码行数:10,代码来源:functions.php


示例11: wpSetUpBeforeClass

 public static function wpSetUpBeforeClass($factory)
 {
     self::$posts[0] = $factory->post->create(array('post_name' => 'post0'));
     self::$posts[1] = $factory->post->create(array('post_name' => 'post1'));
     self::$cats[0] = $factory->category->create(array('slug' => 'cat0'));
     self::$cats[1] = $factory->category->create(array('slug' => 'cat1'));
     self::$cats[2] = $factory->category->create(array('slug' => 'cat2'));
     wp_set_post_categories(self::$posts[0], self::$cats[2]);
     wp_set_post_categories(self::$posts[0], self::$cats[0]);
     wp_set_post_categories(self::$posts[1], self::$cats[1]);
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:11,代码来源:category.php


示例12: test_category_name_change

 /**
  * @ticket 22526
  */
 function test_category_name_change()
 {
     $term = self::factory()->category->create_and_get(array('name' => 'Foo'));
     $post_id = self::factory()->post->create();
     wp_set_post_categories($post_id, $term->term_id);
     $post = get_post($post_id);
     $cats1 = get_the_category($post->ID);
     $this->assertEquals($term->name, reset($cats1)->name);
     wp_update_term($term->term_id, 'category', array('name' => 'Bar'));
     $cats2 = get_the_category($post->ID);
     $this->assertNotEquals($term->name, reset($cats2)->name);
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:15,代码来源:cache.php


示例13: test_should_not_filter_out_duplicate_terms_associated_with_different_objects

 /**
  * @ticket 11003
  */
 public function test_should_not_filter_out_duplicate_terms_associated_with_different_objects()
 {
     $post_id1 = self::factory()->post->create();
     $post_id2 = self::factory()->post->create();
     $cat_id = self::factory()->category->create();
     $cat_id2 = self::factory()->category->create();
     wp_set_post_categories($post_id1, array($cat_id, $cat_id2));
     wp_set_post_categories($post_id2, $cat_id);
     $terms = wp_get_object_terms(array($post_id1, $post_id2), 'category');
     $this->assertCount(2, $terms);
     $this->assertEquals(array($cat_id, $cat_id2), wp_list_pluck($terms, 'term_id'));
     $terms2 = wp_get_object_terms(array($post_id1, $post_id2), 'category', array('fields' => 'all_with_object_id'));
     $this->assertCount(3, $terms2);
     $this->assertEquals(array($cat_id, $cat_id, $cat_id2), wp_list_pluck($terms2, 'term_id'));
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:18,代码来源:wpGetObjectTerms.php


示例14: testBuildPostTable

 function testBuildPostTable()
 {
     $this->markTestIncomplete();
     $posts = array((object) array('ID' => 1, 'post_date' => '2009-01-01', 'post_title' => 'Post 1', 'guid' => 'post-1'), (object) array('ID' => 2, 'post_date' => '2009-01-02', 'post_title' => 'Post 2', 'guid' => 'post-2'), (object) array('ID' => 3, 'post_date' => '2009-01-03', 'post_title' => 'Post 3', 'guid' => 'post-3'));
     foreach ($posts as $post) {
         wp_insert_post($post);
     }
     $categories = array(1 => array(1), 2 => array(1), 3 => array(2));
     foreach ($categories as $id => $cats) {
         wp_set_post_categories($id, $cats);
     }
     $output = '<div class="related_posts"><span>Title</span><table class="month-table"><tr><td class="archive-date" align="right">Jan 3, 2009</td><td class="archive-title"><a title="Post 3" href="post-3">Post 3</a></td></tr></table></div>';
     $this->rp->related_categories = array(2);
     $this->assertEquals($output, $this->rp->build_post_table('Title', $posts));
 }
开发者ID:johnbintz,项目名称:comicpress-2.8,代码行数:15,代码来源:ComicPressRelatedPostsTest.php


示例15: 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


示例16: attachCategories

 public static function attachCategories($sectionObject, $postUrl, $postId)
 {
     if (self::postIsInRootCategory($sectionObject->fullUrlPath)) {
         //Do single category
         $catId = self::createRootCategory($sectionObject->name, $sectionObject->slug);
         wp_set_post_categories($postId, $catId);
     } else {
         // get both categories
         $parentSlug = self::getParentSlug($sectionObject->fullUrlPath);
         $parentName = self::getCatfishCategoryNameBySlug($parentSlug, $postUrl);
         $parentId = self::createRootCategory($parentName, $parentSlug);
         $catId = self::createChildCategory($sectionObject->name, $sectionObject->slug, $parentId);
         wp_set_post_categories($postId, $catId);
     }
 }
开发者ID:shortlist-digital,项目名称:agreable-catfish-importer-plugin,代码行数:15,代码来源:Category.php


示例17: testFindFile

 /**
  * @dataProvider providerTestFindFile
  */
 function testFindFile($files_to_setup, $search_path, $post_categories, $expected_path_result)
 {
     global $post;
     mkdir(vfsStream::url('root/parent/partials/comic/chapter-1'), 0777, true);
     mkdir(vfsStream::url('root/child/partials/comic/chapter-1'), 0777, true);
     foreach ($files_to_setup as $path) {
         file_put_contents(vfsStream::url($path), "test");
     }
     _set_template_directory(vfsStream::url('root/parent'));
     _set_stylesheet_directory(vfsStream::url('root/child'));
     $post = (object) array('ID' => 1);
     wp_set_post_categories(1, array(2));
     add_category(1, (object) array('slug' => 'comic', 'parent' => 0));
     add_category(2, (object) array('slug' => 'chapter-1', 'parent' => 1));
     $this->assertEquals($expected_path_result, $this->cp->find_file('index.inc', $search_path, $post_categories));
 }
开发者ID:johnbintz,项目名称:comicpress-core,代码行数:19,代码来源:ComicPressTest.php


示例18: testSkipEmptyCategories

 function testSkipEmptyCategories()
 {
     global $wp_query;
     $dbi = $this->getMock('ComicPressDBInterface', array('get_previous_post', 'get_next_post', 'get_first_post', 'get_last_post'));
     $storyline = new ComicPressStoryline();
     $storyline->_structure = array('1' => array('next' => 2), '2' => array('previous' => 1, 'next' => 3), '3' => array('previous' => 2));
     wp_insert_post(array('ID' => 1));
     $post = get_post(1);
     wp_set_post_categories(1, array(1));
     $dbi->expects($this->any())->method('get_first_post')->will($this->returnCallback(array(&$this, 'callbackTestSkipEmptyCategories')));
     $this->nav->_dbi = $dbi;
     $this->nav->_storyline = $storyline;
     $wp_query = (object) array('is_single' => true, 'in_the_loop' => true);
     $nav = $this->nav->get_post_nav($post);
     $this->assertEquals(10, $nav['storyline-chapter-next']->ID);
 }
开发者ID:johnbintz,项目名称:comicpress-core,代码行数:16,代码来源:ComicPressNavigationTest.php


示例19: wpc_update_post_terms

function wpc_update_post_terms($post_id)
{
    if ($parent = wp_is_post_revision($post_id)) {
        $post_id = $parent;
    }
    $post = get_post($post_id);
    if ($post->post_type != 'cpt-00-01') {
        return;
    }
    // add a category
    $categories = wp_get_post_categories($post_id);
    // make sure these category names already exists. They are not created automatically.
    $newcat1 = get_term_by('slug', 'cat-00-01', 'category');
    array_push($categories, $newcat1->term_id);
    wp_set_post_categories($post_id, $categories);
}
开发者ID:rhaubt,项目名称:Rock-Art-Database-RADB-,代码行数:16,代码来源:functions.php


示例20: quiz_import

 function quiz_import()
 {
     if (wp_verify_nonce($_POST['nonce'], "molie_admin_quiz")) {
         $post = get_post($_POST['course_post']);
         $categories = $this->create_categories($post);
         $quiz = $this->get_quiz($post);
         print_r($quiz);
         if (get_post_meta($post->ID, "canvasQuiz_" . $quiz->id, true) == "") {
             $quiz_post = wp_insert_post(array("post_type" => 'linkedcanvasquiz', "post_status" => 'publish', "post_title" => $quiz->title, "post_content" => $quiz->description, "post_author" => get_current_user_id()));
             wp_set_post_categories($quiz_post, $categories);
             update_post_meta($quiz_post, "CanvasCourse", get_post_meta($post->ID, "courseID", true), true);
             update_post_meta($quiz_post, "canvasQuizURL", $quiz->html_url, true);
             update_post_meta($post->ID, "canvasQuiz_" . $quiz->id, $quiz_post, true);
         } else {
             $quiz_post = get_post_meta($post->ID, "canvasQuiz_" . $quiz->id, true);
         }
         $questions = $this->get_quiz_questions($post);
         foreach ($questions as $question) {
             if (get_post_meta($quiz_post, "canvasQuizQuestion_" . $question->id, true) == "") {
                 $question_post = wp_insert_post(array("post_type" => 'linkedcanvasqa', "post_status" => 'publish', "post_title" => $quiz->title . " " . $question->question_name, "post_content" => $question->question_text, "post_author" => get_current_user_id()), true);
                 wp_set_post_categories($question_post, $categories);
                 update_post_meta($question_post, "CanvasCourse", get_post_meta($post->ID, "courseID", true), true);
                 update_post_meta($question_post, "canvasQuiz", $question->quiz_id, true);
                 update_post_meta($question_post, "canvasQuizWPPost", $quiz_post, true);
                 update_post_meta($question_post, "canvasQuestion_id", $question->id, true);
                 update_post_meta($question_post, "canvasQuestion_position", $question->position, true);
                 update_post_meta($quiz_post, "canvasQuizQuestion_" . $question->id, $question_post, true);
                 if ($question->question_type == "multiple_choice_question") {
                     $counter = 1;
                     foreach ($question->answers as $answer) {
                         print_r($answer);
                         update_post_meta($question_post, "qa_id_" . $counter, $answer->id, true);
                         update_post_meta($question_post, "qa_weight_" . $counter, $answer->weight, true);
                         update_post_meta($question_post, "qa_answer_" . $counter, $answer->text, true);
                         update_post_meta($question_post, "qa_feedback_" . $counter, $answer->comments, true);
                         $counter++;
                     }
                 }
             }
         }
         echo __("Quiz linked");
     } else {
         print_r($_POST);
         echo "Nonce failed";
     }
     wp_die();
 }
开发者ID:pgogy,项目名称:WordPress-MOLIE,代码行数:47,代码来源:molie-quiz-ajax.php



注:本文中的wp_set_post_categories函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_set_post_cats函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_set_password函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap