0

I have a WP theme with its own custom fields. I installed the PowerPress Plugin. The PowerPress Plugin has a textfield called 'Episode Titles'.

What I want is when the post is published (or save), WP will grab the data from the custom field 'Speaker' and then populated it into 'Episode Titles'.

Can someone show me how to do this? I know how to populate a custom field when publish -> Automatically fill custom field value on post publish/update

1
/* Do something with the data entered */
add_action( 'save_post', 'myplugin_save_postdata' );

/* When the post is saved, saves our custom data */
function myplugin_save_postdata( $post_id ) {

  // First we need to check if the current user is authorised to do this action. 
  if ( 'page' == $_POST['post_type'] ) {// checks for post type.
    if ( ! current_user_can( 'edit_page', $post_id ) )
        return;
  } else {
    if ( ! current_user_can( 'edit_post', $post_id ) )
        return;
  }

  $mydata = get_post_meta($post_id,'speaker',true);

  update_post_meta( $post_id, '_your_meta_key', $mydata ); // replace your _your_meta_key with Episode Titles key

}

This might be what you need. The current code works for pages only, but can be modified to work with posts or CPTs aswell.

What this does is, it grabs the data from your speaker field and updates that value into your episode title. Be sure to add the correct key for your Episode Titles

  • Thanks for the help. Unfortunately, it won't work for PowerPress Plugin. When i check the meta box fields PowerPress adds, they are adding HTML code to insert the meta boxes. The name of the input field is "Powerpress[podcast][feed_title]". The ID is "powerpress_feed_title_podcast". I tried both in the function code and it doesn't work. :( I suspect it is the way PowerPress create the meta box fields (using HTML tags) that is causing an error. – BigRedDog Aug 16 '16 at 7:09
  • Sorry but i have a bit more issue with this. When I use 'save post', i only shows up when i create a new post. When i save an existing post, the data is not updated. – BigRedDog Aug 16 '16 at 9:17
  • @BigRedDog Did you replace the '_your_meta_key' with you're own metakey? Also could you let me know what meta is your meta key – bagpipper Aug 16 '16 at 11:49
  • This is my problem. The meta key for PowerPress plugin has a diff format than other meta key (for meta box). In the metabox.php code for this plugin, the name of the meta key is "Powerpress[<?php echo $FeedSlug; ?>][feed_title]". From the code in the create a post page, the field is Powerpress[podcast]‌​[feed_title]. It looks like the plugin uses an array to store the meta data thus the format is diff with square brackets. – BigRedDog Aug 17 '16 at 3:56
  • I figured this out. The problem is that the plugin stores all the data as one value in the meta_value. This is what the value is stored as (along with other values) -> "media.cscc.org.sg/vodcast/media/… 112742479 video/mp4 a:4:{s:8:"duration";s:7:"0:40:52";s:8:"subtitle";s:24:"cliffasdfasdfaaasdfasdfa";s:6:"author";s:24:"cliffasdfasdfaaasdfasdfa";s:10:"feed_title";s:24:"cliffasdfasdfaaasdfasdfa";}" I guess there's not much i can do unless i really want to do some search and replace values. – BigRedDog Aug 23 '16 at 9:11
0

I am the lead developer of PowerPress. Please let me know if you have any questions.

I would recommend developing a plugin to do what you need rather than put this in your theme's functions.php since this functionality may live beyond your current theme.

Can you explain what your end goal is? There may be an easier solution. PowerPress uses multi-dimensional arrays for the values as you can have more than one podcast episode box per blog post using custom post types or podcast channels features in PowerPress, which may be overkill for your use.

  • Hi @Angelo, Thanks for commenting. This is what I like to do. I have a post type, sermon, which has its own meta boxes (sermon speaker and sermon date). What I want to do is when I publish the sermon post, it will take the sermon speaker and the sermon data meta data and insert it into the feed title of the podcast. I have set up two feeds (podcast and vodcast). The reason I am doing this is to reduce the manual data entry the user needs to publish in the feed. Thanks! – BigRedDog Aug 17 '16 at 2:52
  • i realized that the data is stored as Text data and not as separate meta_value. Unfortunately, there's not much i can do unless i really want to dig into figuring out how to search and replace. Love your plug in but will be super helpful if the values are kept as separate data under post_meta - meta_values. – BigRedDog Aug 23 '16 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.