Skip to content

Instantly share code, notes, and snippets.

@xavivars
Created October 2, 2009 08:49
Show Gist options
  • Save xavivars/199568 to your computer and use it in GitHub Desktop.
Save xavivars/199568 to your computer and use it in GitHub Desktop.
<?php
## script to add custom fields to magic fields
## version: 0.1
## author: Xavi Ivars (xavi.ivars at gmail.com)
define(WP_ADMIN,true);
include('wp-config.php');
include('wp-load.php');
global $wpdb;
// first we declare custom_fields we want to add to magic_fields (if they exist)
$meta_keys = array('especial','especial_links','font_slug','font_url','cambra_file');
// and also we define data for all those custom_fields
// (we can get it looking at URLs when editing panels,fields,...)
$meta_data = array(
'especial' => array(
'field_id'=>3,
'group_counter'=>1,
'field_counter'=>1,
'group_id'=>3,
'raw_custom_field_name'=>''
),
'especial_links' => array(
'field_id'=>4,
'group_counter'=>1,
'field_counter'=>1,
'group_id'=>5,
'raw_custom_field_name'=>''
),
'font_slug' => array(
'field_id'=>1,
'group_counter'=>1,
'field_counter'=>1,
'group_id'=>2,
'raw_custom_field_name'=>''
),
'font_url' => array(
'field_id'=>2,
'group_counter'=>1,
'field_counter'=>1,
'group_id'=>2,
'raw_custom_field_name'=>''
),
'cambra_file' => array(
'field_id'=>5,
'group_counter'=>1,
'field_counter'=>1,
'group_id'=>7,
'raw_custom_field_name'=>''
)
);
foreach($meta_data as $key=>$value){
$meta_data[$key]['raw_custom_field_name']=RC_Format::GetInputName($key);
}
function xxxx_get_name($name) {
global $meta_data;
$ret = $name;
if(isset($meta_data[$name])) {
$v = $meta_data[$name];
$ret = $v['field_id'].'_'.$v['group_counter'].'_';
$ret .= $v['field_counter'].'_'.$v['group_id'].'_'.$v['raw_custom_field_name'];
}
return $ret;
}
query_posts('posts_per_page=-1&order=ASC');
echo '<ol>';
while( have_posts()) {
the_post();
echo '<li>';
the_title();
echo '<br />';
$custom_field = get_post_custom();
$_POST=array();
$_POST['rc_cwp_meta_keys']=array();
$_POST['rc-cwp-custom-write-panel-id'] = $custom_field['_mf_write_panel_id'][0];
foreach($custom_field as $key => $value) {
if(in_array($key, $meta_keys)) {
$_POST['rc_cwp_meta_keys'][]=xxxx_get_name($key);
$_POST[xxxx_get_name($key)]=$value[0];
}
}
echo '<pre>';
print_r($_POST);
echo '</pre>';
RCCWP_Post::SetMetaValues(get_the_ID());
echo '</li>';
}
echo '</ol>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment