我今天犯了一个大错误,使用插件将1000多个价格自定义字段转换为价格下的子类别。我不知道转换后自定义字段会被删除。
价格仍然附在各自的帖子上,如果有人能帮助我使用sql查询将值复制回价格自定义字段,我将不胜感激。
这是我的职责。php包括您的代码
<?php
//get all categories ID\'s in to array
$args = array( \'child_of\' =>3678);
$categories = get_categories( $args );
$cat_array = array();
foreach ($categories as $category) {
$cat_array[] = $category->term_id;
}
$Query_args = array(
\'category__in\' =>$cat_array );
$new_query = new WP_Query();
$new_query->query($Query_args);
if ($new_query->have_posts()){
while ($new_query->have_posts()){
$new_query->the_post();
foreach((get_the_category()) as $category) {
if (in_array($category->cat_ID,$cat_array){
update_post_meta($post_id, \'price\', $category->cat_name);
}
}
}
}
/*************************************************************
* Do not modify unless you know what you\'re doing, SERIOUSLY!
*************************************************************/
/* Admin framework version 2.0 by Zeljan Topic */
// Theme variables
require_once (TEMPLATEPATH . \'/library/functions/theme_variables.php\');
//** ADMINISTRATION FILES **//
// Theme admin functions
require_once ($functions_path . \'admin_functions.php\');
// Theme admin options
require_once ($functions_path . \'admin_options.php\');
// Theme admin Settings
require_once ($functions_path . \'admin_settings.php\');
//** FRONT-END FILES **//
// Widgets
require_once ($functions_path . \'widgets_functions.php\');
// Comments
require_once ($functions_path . \'comments_functions.php\');
// Yoast\'s plugins
require_once ($functions_path . \'yoast-breadcrumbs.php\');
require_once ($functions_path . \'yoast-posts.php\');
//require_once ($functions_path . \'yoast-canonical.php\');
require_once ($functions_path . \'yoast-breadcrumbs.php\');
/////////shopping cart new function files
require($functions_path . "general_functions.php");
require($functions_path . "cart.php");
require($functions_path . "product.php");
require($functions_path . "custom.php");
require(TEMPLATEPATH . "/product_menu.php");
// Custom
require_once ($functions_path . \'custom_functions.php\');
///message - language file
require(TEMPLATEPATH . "/message.php");
if(\'themes.php\' == basename($_SERVER[\'SCRIPT_FILENAME\']) && $_REQUEST[\'page\']==\'\')
{
if($_REQUEST[\'dummy\']==\'del\')
{
delete_dummy_data();
echo THEME_DUMMY_DELETE_MESSAGE;
}
$post_counts = $wpdb->get_var("select count(post_id) from $wpdb->postmeta where meta_key=\'pt_dummy_content\'");
if(($_REQUEST[\'template\']==\'\' && $post_counts>0 && $_REQUEST[\'page\']==\'\') || $_REQUEST[\'activated\']==\'true\')
{
echo THEME_ACTIVE_MESSAGE;
}
if($_REQUEST[\'activated\'])
{
require_once (TEMPLATEPATH . \'/auto_install.php\');
}
}
function delete_dummy_data()
{
global $wpdb;
$productArray = array();
$pids_sql = "select p.ID from $wpdb->posts p join $wpdb->postmeta pm on pm.post_id=p.ID where meta_key=\'pt_dummy_content\' and meta_value=1";
$pids_info = $wpdb->get_results($pids_sql);
foreach($pids_info as $pids_info_obj)
{
wp_delete_post($pids_info_obj->ID);
}
}
?>
最合适的回答,由SO网友:Bainternet 整理而成
将此代码粘贴到主题的函数中。php文件
//get all categorie ID\'s in to array
$args = array( \'child_of\' => 3678); // Parent category ID
$categories = get_categories( $args );
$cat_array = array();
foreach ($categories as $category) {
$cat_array[] = $category->term_id;
}
$Query_args = array(
\'category__in\' => $cat_array,
\'post_type\' => \'YOUR_POST_TYPE_NAME\'
);
$new_query = new WP_Query();
$new_query->query($Query_args);
if ($new_query->have_posts()){
while ($new_query->have_posts()){
$new_query->the_post();
foreach((get_the_category()) as $category) {
if (in_array($category->cat_ID,$cat_array)){
update_post_meta($post_id, \'price\', $category->cat_name);
}
}
}
}
将“父类别ID”替换为价格类别ID,然后保存该文件,然后删除此代码并再次保存。