本文整理汇总了PHP中set_post_type函数的典型用法代码示例。如果您正苦于以下问题:PHP set_post_type函数的具体用法?PHP set_post_type怎么用?PHP set_post_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_post_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: update_post_type
public function update_post_type($post_id, $link, $post_type)
{
if ($post_type === 'idx_page') {
global $wpdb;
$wpdb->update($wpdb->prefix . "posts", array('post_name' => $link, 'post_type' => 'idx_page'), array('ID' => $post_id));
} else {
$post = get_post($post_id);
$link = $post->post_name;
set_post_type($post_id, $post_type);
}
}
开发者ID:jdelia,项目名称:wordpress-plugin,代码行数:11,代码来源:migrate-old-table.php
示例2: update_post_type
public function update_post_type($post_info)
{
$meta_keys = array('_agent_title' => '_employee_title', '_agent_license' => '_employee_license', '_agent_designations' => '_employee_designations', '_agent_phone' => '_employee_phone', '_agent_mobile' => '_employee_mobile', '_agent_email' => '_employee_email', '_agent_website' => '_employee_website', '_agent_address' => '_employee_address', '_agent_city' => '_employee_city', '_agent_state' => '_employee_state', '_agent_zip' => '_employee_zip', '_agent_facebook' => '_employee_facebook', '_agent_twitter' => '_employee_twitter', '_agent_linkedin' => '_employee_linkedin', '_agent_googleplus' => '_employee_googleplus', '_agent_pinterest' => '_employee_pinterest', '_agent_youtube' => '_employee_youtube', '_agent_instagram' => '_employee_instagram');
foreach ($post_info as $post) {
foreach ($meta_keys as $old_key => $new_key) {
$old_value = get_post_meta($post->ID, $old_key, true);
update_post_meta($post->ID, $new_key, $old_value);
}
set_post_type($post->ID, 'employee');
}
}
开发者ID:agentevolution,项目名称:impress-agents,代码行数:11,代码来源:class-migrate-old-posts.php
示例3: create_plot
/**
* this method is called when the /plots url is hit using a POST method as defined in the register routes above
* @param [type] $data : the data in the post
* @return [string] $new_data: geojson data served in response to the post - just the same posted data served back
*/
function create_plot($data)
{
if (!empty($type) && $type !== $this->type) {
return new WP_Error('json_post_invalid_type', __('Invalid post type'), array('status' => 400));
}
$retval = $this->insert_post($data);
if (is_wp_error($retval)) {
return $retval;
}
// convert to post type
set_post_type($retval, 'plots');
// add geojson meta data
add_post_meta($retval, 'map_data', $data['plot'], true);
// add the area type
wp_set_object_terms($retval, $data['areatype'], 'area-type');
// add the suggested use types
$suggestedUses = explode(',', $data['suggestedUses']);
wp_set_object_terms($retval, $suggestedUses, 'suggested-use');
if (isset($data['imageId'])) {
set_post_thumbnail($retval, $data['imageId']);
}
$data = (array) get_post($retval, 'view');
// hack :-(
$keys_to_remove = ['post_status', 'post_type', 'post_parent', 'post_link', 'post_format', 'post_slug', 'post_guid', 'post_menu_order', 'post_comment_status', 'post_ping_status', 'post_sticky', 'post_meta', 'post_date', 'post_modified', 'post_date_tz', 'post_date_gmt', 'post_modified_tz', 'post_modified_gmt', 'post_terms', 'post_author', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_content_filtered', 'guid', 'menu_order', 'post_mime_type', 'comment_count', 'filter'];
if ($data['post_type'] === EDIBLE_POST_TYPE) {
$data['geo_json'] = get_post_meta($data['ID'])['map_data'];
foreach ($keys_to_remove as $key) {
unset($data[$key]);
}
}
if (has_post_thumbnail($data['ID'])) {
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($data['ID']));
}
// this is slighly complex to gather the terms into an array
$suggestedUsesTerms = get_the_terms($data['ID'], 'suggested-use');
$suggestedUses = array();
if ($suggestedUsesTerms) {
foreach ($suggestedUsesTerms as $key => $term) {
$suggestedUses[] = $term->name;
}
}
$suggestedUses = json_encode($suggestedUses);
//n.b. PHP 5.2 and above
// we should unpack the geojson as it's not properly stored. my bad but hopefully easy to fix..
$new_data = array('id' => $data['ID'], 'title' => $data['post_title'], 'content' => $data['post_content'], 'excerpt' => $data['post_excerpt'], 'geo_json' => $data['geo_json'], 'area_type' => get_the_terms($data['ID'], 'area-type')[0]->name, 'suggested_uses' => $suggestedUses, 'image' => $thumb[0]);
return $new_data;
}
开发者ID:safetycat,项目名称:edibleurban,代码行数:52,代码来源:class-edible-urban-api-plot.php
示例4: testGetPostsNew
function testGetPostsNew()
{
require_once 'php/timber-post-subclass.php';
$term_id = $this->factory->term->create();
$posts = array();
$posts[] = $this->factory->post->create();
$posts[] = $this->factory->post->create();
$posts[] = $this->factory->post->create();
foreach ($posts as $post_id) {
set_post_type($post_id, 'page');
wp_set_object_terms($post_id, $term_id, 'post_tag', true);
}
$term = new TimberTerm($term_id);
$gotten_posts = $term->get_posts('post_type=page');
$this->assertEquals(count($posts), count($gotten_posts));
$gotten_posts = $term->get_posts('post_type=page', 'TimberPostSubclass');
$this->assertEquals(count($posts), count($gotten_posts));
$this->assertEquals($gotten_posts[0]->foo(), 'bar');
$gotten_posts = $term->get_posts(array('post_type' => 'page'), 'TimberPostSubclass');
$this->assertEquals($gotten_posts[0]->foo(), 'bar');
$this->assertEquals(count($posts), count($gotten_posts));
}
开发者ID:aauroux,项目名称:timber,代码行数:22,代码来源:test-timber-term.php
示例5: cp_convert_posts2Ads
function cp_convert_posts2Ads()
{
global $wpdb, $app_version;
echo '<div id="message2" class="updated" style="padding:10px 20px;">';
// setup post conversion and stop if there are no valid ad listings in the posts table to convert
$blogCatIDs = array();
$blogCatIDs = cp_get_blog_cat_ids_array();
// get all posts not in blog cats for quick check
$args = array('category__not_in' => $blogCatIDs, 'post_status' => 'any', 'numberposts' => 10);
$theposts = get_posts($args);
if (count($theposts) < 1) {
wp_die('<h3>Migration script error</h3><p>Process did not run. No ad listings were found. You only have blog posts or your blog parent category ID is incorrect.</p>');
}
// convert all the NON-BLOG categories to be part of the new ad_cat taxonomy
echo '<p>Converting ad categories.........</p>';
// get all category ids
$cat_ids = get_all_category_ids();
$cat_count_total = count($cat_ids);
echo '<ul>';
$cat_count = 0;
foreach ($cat_ids as $cat_id) {
// only move categories not belonging to the blog cats or blog sub cats
if (!in_array($cat_id, $blogCatIDs)) {
$wpdb->update($wpdb->term_taxonomy, array('taxonomy' => APP_TAX_CAT), array('term_id' => $cat_id));
$thisCat = get_category($cat_id);
echo '<li style="color:#009900"><strong>' . $thisCat->name . '</strong> (ID:' . $cat_id . ')' . ' category has been moved</li>';
$cat_count++;
} else {
$thisCat = get_category($cat_id);
echo '<li><strong>' . $thisCat->name . '</strong> (ID:' . $cat_id . ')' . ' category has been skipped</li>';
}
}
echo '</ul>';
//convert all the NON-BLOG posts to be part of the new "ad_listing" taxonomy
echo '<br /><p><strong>Converting posts........</strong></p>';
$newTagsSummary = array();
$post_count = 0;
$ad_count = 0;
$tag_count = 0;
echo '<ul>';
// get all the posts
$args = array('post_status' => 'any', 'numberposts' => -1);
$theposts = get_posts($args);
foreach ($theposts as $post) {
setup_postdata($post);
// get the post terms
$oldTags = wp_get_post_terms($post->ID);
$newTags = array();
// get the cat object array for the post
$post_cats = get_the_category($post->ID);
// grab the first cat id found
$cat_id = $post_cats[0]->cat_ID;
//check if the post is in a blog category
if (!in_array($cat_id, $blogCatIDs)) {
// if yes, then first see if it has any tags
if (!empty($oldTags)) {
foreach ($oldTags as $thetag) {
$newTags[] = $thetag->name;
$newTagsSummary[] = '<li style="color:#009900"><strong>"' . $thetag->name . '"</strong> tag has been copied</li>';
$tag_count++;
}
}
// copy the tag array over if it's not empty
if (!empty($newTags)) {
wp_set_post_terms($post->ID, $newTags, APP_TAX_TAG);
}
//now change the post to an ad
set_post_type($post->ID, APP_POST_TYPE);
echo '<li style="color:#009900"><strong>"' . $post->post_title . '"</strong> (ID:' . $post->ID . ') post was converted</li>';
$ad_count++;
// not an ad so must be a blog post
} else {
// see if it has tags since we still want to echo them not moved
if (!empty($oldTags)) {
foreach ($oldTags as $thetag) {
$newTags[] = $thetag->name;
$newTagsSummary[] = '<li><strong>"' . $thetag->name . '"</strong> tag has been skipped</li>';
//$tag_count++;
}
}
echo '<li><strong>"<a href="post.php?post=' . $post->ID . '&action=edit" target="_blank">' . $post->post_title . '</a>"</strong> (ID:' . $post->ID . ') post has been skipped (in blog or blog-sub category)</li>';
}
$post_count++;
}
echo '<br/><p><strong>Copying tags...........</strong></p>';
// get the total count of tags
$all_tags = get_tags();
$tags_count_total = count($all_tags);
// calculate the results
$blog_cats_total = $cat_count_total - $cat_count;
$blog_posts_total = $post_count - $ad_count;
$blog_tags_total = $tags_count_total - $tag_count;
// print out all the tags
foreach ($newTagsSummary as $key => $value) {
echo $value;
}
echo '</ul><br/>';
echo '<h3>Migration Summary</h3>';
echo '<p>Total categories converted: <strong>' . $cat_count . '/' . $cat_count_total . '</strong> <small>(excluded ' . $blog_cats_total . ' blog categories)</small><br/>';
echo 'Total posts converted: <strong>' . $ad_count . '/' . $post_count . '</strong> <small>(excluded ' . $blog_posts_total . ' blog posts)</small><br/>';
//.........这里部分代码省略.........
开发者ID:joaosigno,项目名称:dazake-job,代码行数:101,代码来源:admin-updates.php
示例6: timetable_ajax_events_settings_save
function timetable_ajax_events_settings_save()
{
$timetable_events_settings = get_option("timetable_events_settings");
$slug_old = $timetable_events_settings["slug"];
$timetable_slug_old = $timetable_events_settings["slug"];
$timetable_events_settings["slug"] = !empty($_POST["events_slug"]) ? $_POST["events_slug"] : __("events", "timetable");
$timetable_events_settings["label_singular"] = !empty($_POST["events_label_singular"]) ? $_POST["events_label_singular"] : __("Event", "timetable");
$timetable_events_settings["label_plural"] = !empty($_POST["events_label_plural"]) ? $_POST["events_label_plural"] : __("Events", "timetable");
if (update_option("timetable_events_settings", $timetable_events_settings) && $timetable_slug_old != $_POST["events_slug"]) {
require_once "post-type-events.php";
$events = get_posts(array('post_type' => $slug_old, 'posts_per_page' => -1));
foreach ($events as $event) {
set_post_type($event->ID, $timetable_events_settings["slug"]);
}
//delete rewrite rules, they will be regenerated automatically by WP on next request
delete_option('rewrite_rules');
}
exit;
}
开发者ID:StudentLifeMarketingAndDesign,项目名称:krui-wp,代码行数:19,代码来源:timetable.php
示例7: bulk_convert_posts
function bulk_convert_posts()
{
// check for invalid post type choices
if ($_POST['new_post_type'] == -1 || $_POST['old_post_type'] == -1) {
echo '<p class="error">' . __('Could not convert posts. One of the post types was not set.', 'convert-post-types') . '</p>';
return;
}
if (!post_type_exists($_POST['new_post_type']) || !post_type_exists($_POST['old_post_type'])) {
echo '<p class="error">' . __('Could not convert posts. One of the selected post types does not exist.', 'convert-post-types') . '</p>';
return;
}
$query = array('posts_per_page' => -1, 'post_status' => 'any', 'post_type' => $_POST['old_post_type']);
if (!empty($_POST['convert_cat']) && $_POST['convert_cat'] > 1) {
$query['cat'] = $_POST['convert_cat'];
}
if (!empty($_POST['page_parent']) && $_POST['page_parent'] > 0) {
$query['post_parent'] = $_POST['page_parent'];
}
$items = get_posts($query);
if (!is_array($items)) {
echo '<p class="error">' . __('Could not find any posts matching your criteria.', 'convert-post-types') . '</p>';
return;
}
global $wp_taxonomies;
foreach ($items as $post) {
// Update the post into the database
$update['ID'] = $post->ID;
if (!($new_post_type_object = get_post_type_object($_POST['new_post_type']))) {
echo '<p class="error">' . sprintf(__('Could not convert post #%d. %s', 'convert-post-types'), $post->ID, _('The new post type was not valid.')) . '</p>';
} else {
// handle post categories now; otherwise all posts will receive the default
if ('post' == $new_post_type_object->name && isset($_POST['post_category']) && !empty($_POST['post_category'])) {
wp_set_post_terms($post->ID, $_POST['post_category'], 'post_category', false);
}
set_post_type($post->ID, $new_post_type_object->name);
// WPML support. Thanks to Jenny Beaumont! http://www.jennybeaumont.com/post-type-switcher-wpml-fix/
if (function_exists('icl_object_id')) {
// adjust field 'element_type' in table 'wp_icl_translations'
// from 'post_OLDNAME' to 'post_NEWNAME'
// the post_id you look for is in column: 'element_id'
if ($post->post_type == 'revision') {
if (is_array($post->ancestors)) {
$ID = $post->ancestors[0];
}
} else {
$ID = $post->ID;
}
global $wpdb;
$wpdb->update($wpdb->prefix . 'icl_translations', array('element_type' => 'post_' . $new_post_type_object->name), array('element_id' => $ID, 'element_type' => 'post_' . $post->post_type));
$wpdb->print_error();
}
}
// set new taxonomy terms
foreach ($wp_taxonomies as $tax) {
// hierarchical custom taxonomies
if (isset($_POST['tax_input'][$tax->name]) && !empty($_POST['tax_input'][$tax->name]) && is_array($_POST['tax_input'][$tax->name])) {
wp_set_post_terms($post->ID, $_POST['tax_input'][$tax->name], $tax->name, false);
echo '<p class="msg">' . sprintf(__('Set %s to %s', 'convert-post-types'), $tax->label, $term->{$name}) . '</p>';
}
// all flat taxonomies
if (isset($_POST[$tax->name]) && !empty($_POST[$tax->name]) && 'post_category' != $tax->name) {
wp_set_post_terms($post->ID, $_POST[$tax->name], $tax->name, false);
if ('post_category' == $tax->name) {
echo '<p class="msg">' . sprintf(__('Set %s to %s', 'convert-post-types'), $tax->label, join(', ', $_POST[$tax->name])) . '</p>';
} else {
echo '<p class="msg">' . sprintf(__('Set %s to %s', 'convert-post-types'), $tax->label, $_POST[$tax->name]) . '</p>';
}
}
}
}
echo '<div class="updated"><p><strong>' . __('Posts converted.', 'convert-post-types') . '</strong></p></div>';
}
开发者ID:astarts,项目名称:htdocs,代码行数:72,代码来源:convert-post-types.php
示例8: update_settings
public function update_settings()
{
$preload = $_POST['preload'];
$postType = $_POST['postType'];
$settings = CubePortfolioMain::$settings;
if ($settings['postType'] !== $postType) {
if (post_type_exists($postType)) {
echo 0;
exit;
}
$query = new WP_Query(array('post_type' => $settings['postType'], 'posts_per_page' => -1));
$postTypesOldArray = array();
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$id = get_the_ID();
$postTypesOldArray[] = get_permalink($id);
set_post_type($id, $postType);
}
// next time when the page is loaded flush the permalinks
$settings['flush_rewrite_rules'] = true;
}
// update cbp items
$this->update_items_postType($postTypesOldArray, $settings['postType'], $postType);
// update taxonomy
$this->wpdb->update('wp_term_taxonomy', array('taxonomy' => $postType . '_category'), array('taxonomy' => $settings['postType'] . '_category'));
$settings['postType'] = $postType;
}
$settings['preload'] = $preload;
update_option('cubeportfolio_settings', $settings);
// send this message to frontend
echo 1;
exit;
}
开发者ID:johnmanlove,项目名称:JMMC_Corp-Site,代码行数:34,代码来源:CubePortfolioBackend.php
示例9: update_plugin_data
/**
* Runs at plugin init. Checks the plugin's version and does updates
* as needed.
*/
public function update_plugin_data()
{
// Get the stored plugin version. If the version is not set, this is a clean installation.
// If the version differs from current version, the plugin has been updated and we'll
// run an update if necessary.
$plugin_version = get_option($this->plugin_name . '_plugin-version', false);
if ($plugin_version == $this->version) {
// Already at current version
return false;
} else {
// The plugin was just updated. Update the version right away to prevent concurrency issues
// with more than one thread running the updates at once.
update_option($this->plugin_name . '_plugin-version', $this->version);
if ($plugin_version === false) {
// This is a clean installation, no need to run updates.
/*
* Exception: Because we added this update functionality only at version 0.5.5 of the plugin,
* we need to make an exception for people running that version.
*
* This is hacky and will lead to some people running the update unnecessarily, but since
* there are still only a small number of installs so far, it's better than not doing it.
*/
if ($this->version == '0.5.5') {
$plugin_version = '0.5.4';
} else {
return false;
}
}
// Do the updates based on previous version
if (version_compare($plugin_version, '0.5.5') < 0) {
// Update product meta box and post type id for old products created before
// the update.
$posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'product'));
foreach ($posts as $post) {
if (get_post_meta($post->ID, 'wp_license_manager_product_meta', true) == '') {
$meta = array();
$meta['file_bucket'] = get_post_meta($post->ID, '_product_file_bucket', true);
$meta['file_name'] = get_post_meta($post->ID, '_product_file_name', true);
$meta['version'] = get_post_meta($post->ID, '_product_version', true);
$meta['tested'] = get_post_meta($post->ID, '_product_tested', true);
$meta['requires'] = get_post_meta($post->ID, '_product_requires', true);
$meta['updated'] = get_post_meta($post->ID, '_product_updated', true);
$meta['banner_low'] = get_post_meta($post->ID, '_product_banner_low', true);
$meta['banner_high'] = get_post_meta($post->ID, '_product_banner_high', true);
update_post_meta($post->ID, 'wp_license_manager_product_meta', $meta);
}
// Update post type to a better name
set_post_type($post->ID, 'wplm_product');
}
}
}
}
开发者ID:wangshipeng,项目名称:wp-license-manager,代码行数:56,代码来源:class-wp-license-manager.php
示例10: badgeos_update_achievements_achievement_types
/**
* Change all achievements of one type to a new type.
*
* @since 1.4.0
*
* @param string $original_type Original achievement type.
* @param string $new_type New achievement type.
*/
function badgeos_update_achievements_achievement_types($original_type = '', $new_type = '')
{
$items = get_posts(array('posts_per_page' => -1, 'post_status' => 'any', 'post_type' => $original_type, 'fields' => 'id'));
foreach ($items as $item) {
set_post_type($item->ID, $new_type);
}
}
开发者ID:Nrddy,项目名称:badgeos,代码行数:15,代码来源:achievement-functions.php
示例11: save_post
/**
* Set the post type on save_post but only when editing
*
* We do a bunch of sanity checks here, to make sure we're only changing the
* post type when the user explicitly intends to.
*
* - Not during autosave
* - Check nonce
* - Check user capabilities
* - Check $_POST input name
* - Check if revision or current post-type
* - Check new post-type exists
* - Check that user can publish posts of new type
*
* @since 1.0.0
*
* @param int $post_id
* @param object $post
*
* @return If any number of condtions are met
*/
public function save_post($post_id, $post)
{
// Post type information.
$post_type = $_REQUEST['pts_post_type'];
$post_type_object = get_post_type_object($post_type);
// Add nonce for security and authentication.
$nonce_name = $_REQUEST['pts-nonce-select'];
$nonce_action = 'post-type-selector';
// Check if a nonce is set.
if (!isset($nonce_name)) {
return;
}
// Check if a nonce is valid.
if (!wp_verify_nonce($nonce_name, $nonce_action)) {
return;
}
// Check if the user has permissions to 'edit_post'.
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Check if it's not an autosave.
if (wp_is_post_autosave($post_id)) {
return;
}
// Check if it's not a revision.
if (wp_is_post_revision($post_id)) {
return;
}
// Check if a post type is set.
if (empty($post_type)) {
return;
}
// Check if a post type object is set.
if (empty($post_type_object)) {
return;
}
// Check if it's not a revision.
if (in_array($post->post_type, array($post_type, 'revision'), true)) {
return;
}
// Check if the user has permissions to 'publish_posts'.
if (!current_user_can($post_type_object->cap->publish_posts)) {
return;
}
// Set the new post type.
set_post_type($post_id, $post_type_object->name);
}
开发者ID:adrianjonmiller,项目名称:nilslindstrom,代码行数:68,代码来源:post-type-switcher.php
示例12: upgradeData
/**
* Will upgrade data from old free plugin to pro plugin
*/
public static function upgradeData()
{
$num_upgraded = 0;
if (isset($_POST['upgradeEventsCalendar']) && check_admin_referer('upgradeEventsCalendar')) {
/*
TODO: migrate the following:
* option "sp_events_calendar_options" needs to be renamed as TribeEvents::OPTIONNAME
* posts of type "sp_events" need to be moved to TribeEvents::POSTTYPE
* posts of type "sp_venue" need to be moved to TribeEvents::VENUE_POST_TYPE
* posts of type "sp_organizer" need to be moved to TribeEvents::ORGANIZER_POST_TYPE
* categories of type "sp_events_cat" need to be moved to TribeEvents::TAXONOMY
* options that saved using on/enabled/yes need to be set to 1 and off/disabled/no being 0
* update plugin meta for EVERY event post meta to replace on/enabled/yes with 1 and off/disabled/no to be 0
*/
$posts = self::getLegacyEvents();
// we don't want the old event category
$eventCat = get_term_by('name', 'Events', 'category');
// existing event cats
$existingEventCats = (array) get_terms(TribeEvents::TAXONOMY, array('fields' => 'names'));
// store potential new event cats;
$newEventCats = array();
// first create log needed new event categories
foreach ($posts as $key => $post) {
// we don't want the old Events category
$cats = self::removeEventCat(get_the_category($post->ID), $eventCat);
// see what new ones we need
$newEventCats = self::mergeCatList($cats, $newEventCats);
// store on the $post to keep from re-querying
$posts[$key]->cats = self::getCatNames($cats);
}
// dedupe
$newEventCats = array_unique($newEventCats);
// let's create new events cats
foreach ($newEventCats as $cat) {
// leave alone existing ones
if (in_array($cat, $existingEventCats)) {
continue;
}
// make 'em!
wp_insert_term($cat, TribeEvents::TAXONOMY);
}
// now we know what we're in for
$masterCats = get_terms(TribeEvents::TAXONOMY, array('hide_empty' => false));
// let's convert those posts
foreach ($posts as $post) {
// new post_type sir
set_post_type($post->ID, TribeEvents::POSTTYPE);
// set new events cats. we stored the array above, remember?
if (!empty($post->cats)) {
wp_set_object_terms($post->ID, $post->cats, TribeEvents::TAXONOMY);
}
self::convertVenue($post);
// Translate the post's setting for google maps display
self::translateGoogleMaps($post);
$num_upgraded++;
}
if ($num_upgraded > 0) {
self::$upgradeMessage = sprintf(__('You successfully migrated (%d) entries.', 'tribe-events-calendar'), $num_upgraded);
}
}
}
开发者ID:mpaskew,项目名称:isc-dev,代码行数:66,代码来源:tribe-the-events-calendar-import.class.php
示例13: activate
/**
* Prepares sites to use the plugin during single or network-wide activation
*
* @since 1.0
*
* @param bool $network_wide
*/
public function activate($network_wide)
{
global $wpdb;
$contents = $wpdb->get_results("SELECT DISTINCT post_id\n\t\t\t\t FROM {$wpdb->postmeta}\n\t\t\t\t WHERE meta_key IN ('_wpml_content_type', '_wpmoly_content_type')\n\t\t\t\t AND meta_value='movie'");
foreach ($contents as $p) {
set_post_type($p->post_id, 'movie');
delete_post_meta($p->post_id, '_wpmoly_content_type', 'movie');
delete_post_meta($p->post_id, '_wpml_content_type', 'movie');
}
self::register_post_type();
}
开发者ID:masterdoed,项目名称:wpmovielibrary,代码行数:18,代码来源:class-wpmoly-movies.php
示例14: save_post
/**
* Set the post type on save_post but only when editing
*
* We do a bunch of sanity checks here, to make sure we're only changing the
* post type when the user explicitly intends to.
*
* - Not during autosave
* - Check nonce
* - Check user capabilities
* - Check $_POST input name
* - Check if revision or current post-type
* - Check new post-type exists
* - Check that user can publish posts of new type
*
* @since PostTypeSwitcher (0.3)
* @param int $post_id
* @param object $post
* @return If any number of condtions are met
*/
public function save_post($post_id, $post)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!isset($_REQUEST['pts-nonce-select'])) {
return;
}
if (!wp_verify_nonce($_REQUEST['pts-nonce-select'], 'post-type-selector')) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
if (empty($_REQUEST['pts_post_type'])) {
return;
}
if (in_array($post->post_type, array($_REQUEST['pts_post_type'], 'revision'))) {
return;
}
if (!($new_post_type_object = get_post_type_object($_REQUEST['pts_post_type']))) {
return;
}
if (!current_user_can($new_post_type_object->cap->publish_posts)) {
return;
}
set_post_type($post_id, $new_post_type_object->name);
}
开发者ID:phupx,项目名称:genco,代码行数:47,代码来源:post-type-switcher.php
示例15: process_bulk_action
function process_bulk_action()
{
global $wp_rewrite, $wpdb;
if ('convert' === $this->current_action()) {
$output = "<div id=\"viceversa-status\" class=\"updated\">\n <input type=\"button\" class=\"viceversa-close-icon button-secondary\" title=\"Close\" value=\"x\" />";
if (VICEVERSA_DEBUG) {
$output .= "<strong>" . __('Debug Mode', 'vice-versa') . "</strong>\n";
}
switch ($_POST['p_type']) {
case 'page':
$categories = array('ids' => array(), 'titles' => array());
$do_bulk = false;
foreach ($_POST['parents'] as $category) {
if ($category != "") {
$data = explode("|", $category);
$categories[$data[3]]['ids'] = array();
$categories[$data[3]]['titles'] = array();
if ($data[3] == 0) {
$do_bulk = true;
}
}
}
foreach ($_POST['parents'] as $category) {
if ($category != "") {
$data = explode("|", $category);
array_push($categories[$data[3]]['ids'], $data[0]);
array_push($categories[$data[3]]['titles'], $data[2]);
}
}
$output .= "<p>\n";
foreach ($_POST['post'] as $viceversa_page) {
$viceversa_data = explode("|", $viceversa_page);
$viceversa_url = site_url() . "/?p=" . $viceversa_data[0];
if ($do_bulk) {
$ids = $categories[0]['ids'];
$titles = $categories[0]['titles'];
} else {
$ids = $categories[$viceversa_data[0]]['ids'];
$titles = $categories[$viceversa_data[0]]['titles'];
}
$catlist = "";
if ($titles) {
foreach ($titles as $cat) {
$catlist .= $cat . ", ";
}
}
$catlist = trim($catlist, ', ') == "" ? get_cat_name(1) : trim($catlist, ', ');
$cat_array = count($ids) < 1 ? array(1) : $ids;
if (!VICEVERSA_DEBUG) {
$wpdb->update($wpdb->posts, array('guid' => $viceversa_url, 'post_parent' => $cat_array[0]), array('ID' => intval($viceversa_data[0])), array('%s', '%d'), array('%d'));
clean_page_cache(intval($viceversa_data[0]));
set_post_type(intval($viceversa_data[0]), 'post');
wp_set_post_categories(intval($viceversa_data[0]), $cat_array);
}
$new_permalink = get_permalink(intval($viceversa_data[0]));
$output .= sprintf(__('<strong>' . __('Page', 'vice-versa') . '</strong> #%s <code><a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">%s</a></code> ' . __('was successfully converted to a <strong>Post</strong> and assigned to category(s)', 'vice-versa') . ' <code>%s</code>. <a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">' . __('New Permalink', 'vice-versa') . '</a>', 'vice-versa'), $viceversa_data[0], $new_permalink, $viceversa_data[2], $catlist, $new_permalink) . "<br />\n";
}
if (!VICEVERSA_DEBUG) {
$wp_rewrite->flush_rules();
}
break;
default:
$parents = array();
$do_bulk = false;
foreach ($_POST['parents'] as $parent) {
if ($parent != "") {
$data = explode("|", $parent);
if ($data[3] == 0) {
$do_bulk = true;
}
$parents[intval($data[3])] = $data[0] . "|" . $data[2];
}
}
$output .= "<p>\n";
if (!$_POST['post']) {
$output .= __('No items were selected. Please select items using the checkboxes.', 'vice-versa');
} else {
foreach ($_POST['post'] as $viceversa_post) {
$viceversa_data = explode("|", $viceversa_post);
$viceversa_url = site_url() . "/?page_id=" . $viceversa_data[0];
if ($do_bulk) {
$p = $parents[0];
} else {
$p = $parents[$viceversa_data[0]];
}
$parent = $p == "" ? "0|" . __('No Parent', 'vice-versa') . "" : $p;
$parent = explode("|", $parent);
if (!VICEVERSA_DEBUG) {
$wpdb->update($wpdb->posts, array('guid' => $viceversa_url, 'post_parent' => intval($parent[0])), array('ID' => intval($viceversa_data[0])), array('%s', '%d'), array('%d'));
clean_post_cache(intval($viceversa_data[0]));
set_post_type(intval($viceversa_data[0]), 'page');
wp_set_post_categories(intval($viceversa_data[0]), array(intval($parent[0])));
}
$permalink = get_permalink(intval($viceversa_data[0]));
$output .= sprintf(__('<strong>' . __('Post', 'vice-versa') . '</strong> #%s <code><a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">%s</a></code> ' . __('was successfully converted to a <strong>Page</strong> and assigned to parent', 'vice-versa') . ' #%s <code>%s</code>. <a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">' . __('New Permalink', 'vice-versa') . '</a>', 'vice-versa'), $viceversa_data[0], $permalink, $viceversa_data[2], $parent[0], $parent[1], $permalink) . "<br />\n";
}
if (!VICEVERSA_DEBUG) {
$wp_rewrite->flush_rules();
}
}
//.........这里部分代码省略.........
开发者ID:jasonlau,项目名称:Wordpress-Vice-Versa,代码行数:101,代码来源:vice-versa.php
示例16: get_the_terms
$terms = get_the_terms($recipe->ID, $tag);
if ($terms !== false && !is_wp_error($terms)) {
$term_ids = array();
foreach ($terms as $term) {
$existing_term = term_exists($term->name, $tag);
$term_ids[] = (int) $existing_term['term_id'];
}
wp_set_object_terms($post->ID, $term_ids, $tag);
}
}
// Photo
$photo_id = get_post_thumbnail_id($recipe->ID);
if ($photo_id != '' && $photo_id != false) {
set_post_thumbnail($post->ID, $photo_id);
}
// Change the slug of the recipe so we don't have any collisions
$update_slug = array('ID' => $recipe_id, 'post_name' => $recipe->post_name . '-recipe');
wp_update_post($update_slug);
// Change post content shortcode
$update_content = array('ID' => $post_id, 'post_content' => preg_replace("/\\[ultimate-recipe\\s[^]]+]/", "[recipe]", $post->post_content));
wp_update_post($update_content);
// Move recipe to trash
wp_trash_post($recipe->ID);
// Switch post type to recipe
set_post_type($post->ID, 'recipe');
$migrate_result[] = array('recipe' => $recipe_id, 'migrated' => true);
}
}
}
}
var_dump($migrate_result);
开发者ID:robertoperata,项目名称:bbqverona.com,代码行数:31,代码来源:special_recipes_to_posts.php
示例17: process_products
//.........这里部分代码省略.........
update_post_meta($id, '_sale_price_dates_from', '');
// sale_price_dates_to
update_post_meta($id, '_sale_price_dates_to', '');
// visibility: visible
update_post_meta($id, '_visibility', 'visible');
// featured: yes / no
$featured_ids = get_option('sticky_products');
if (!is_array($featured_ids)) {
$featured_ids = array($featured_ids);
}
$featured = in_array($id, $featured_ids) ? 'yes' : 'no';
update_post_meta($id, '_featured', $featured);
// sku:
if (isset($meta['_wpsc_sku'][0])) {
update_post_meta($id, '_sku', $meta['_wpsc_sku'][0]);
delete_post_meta($id, '_wpsc_sku');
}
// stock_status : instock / outofstock
// manage_stock : yes / no
// stock : external = 0
// backorders : no
if (isset($meta['_wpsc_stock'][0])) {
if ($meta['_wpsc_stock'][0] === '') {
update_post_meta($id, '_stock_status', 'instock');
update_post_meta($id, '_manage_stock', 'no');
update_post_meta($id, '_stock', '0');
update_post_meta($id, '_backorders', 'no');
} elseif ($meta['_wpsc_stock'][0] === '0') {
update_post_meta($id, '_stock_status', 'outofstock');
update_post_meta($id, '_manage_stock', 'yes');
update_post_meta($id, '_stock', '0');
update_post_meta($id, '_backorders', 'no');
} elseif ($meta['_wpsc_stock'][0] > 0) {
update_post_meta($id, '_stock_status', 'instock');
update_post_meta($id, '_manage_stock', 'yes');
update_post_meta($id, '_stock', $meta['_wpsc_stock'][0]);
update_post_meta($id, '_backorders', 'no');
}
}
// virtual (yes/no)
update_post_meta($id, '_virtual', 'no');
// downloadable (yes/no)
|
请发表评论