LoginSignup
3
3

More than 5 years have passed since last update.

wp post branchesがcustom field suiteで作った値を引き継がない問題を強引に解決

Last updated at Posted at 2014-04-11

custom field suiteが通常のカスタムフィールドを使用せず、独自UIを使用しているため、ブランチ作成時にカスタムフィールドの値が引き継がれない問題が起こっていた。
custom field suiteのAPIを使用してブランチに値をコピーして解決。

ブランチ作成時

wp-post-branches.php_47行目前後
global $cfs;
$options = array('format' => 'raw');
$field_data = $cfs->get(false, $id, $options);
$post_data = array('ID' => $draft_id);
$cfs->save($field_data, $post_data);

// postmeta
// $keys = get_post_custom_keys( $id );
// $custom_field = array();
// foreach ( (array) $keys as $key ) {
//  if ( preg_match( '/^_feedback_/', $key ) )
//      continue;

//  if ( preg_match( '/_wp_old_slug/', $key ) )
//      continue;

//  $key = apply_filters( 'wpbs_publish_to_draft_postmeta_filter', $key );

//  $values = get_post_custom_values($key, $id );

//  foreach ( $values as $value ) {
//      add_post_meta( $draft_id, $key, $value );
//  }
// }

記事公開時

wp-post-branches.php_180行目前後
global $cfs;
$options = array('format' => 'raw');
$field_data = $cfs->get(false, $id, $options);
$post_data = array('ID' => $org_id);
$cfs->save($field_data, $post_data);


//postmeta
// $keys = get_post_custom_keys( $id );

// $custom_field = array();
// foreach ( (array) $keys as $key ) {
//  if ( preg_match( '/^_feedback_/', $key ) )
//      continue;

//  if ( preg_match( '/_wpbs_pre_post_id/', $key ) )
//      continue;

//  if ( preg_match( '/_wp_old_slug/', $key ) )
//      continue;

//  $key = apply_filters( 'wpbs_draft_to_publish_postmeta_filter', $key );

//  delete_post_meta( $org_id, $key );
//  $values = get_post_custom_values($key, $id );
//  foreach ( $values as $value ) {
//      add_post_meta( $org_id, $key, $value );
//  }
// }

custom field suite有効時のみの判別をしたい。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3