I have a custom post type that doesn't use the default title bar to define the post's title. Instead it is a series of taxonomies: artist, album and year.

Right now my xml feed is displaying <title>Auto Draft</title> for each post type. What filter can I use to have these three taxonomies be the post type's title tag in the feed?

1 Answer 1


You can use wp_insert_post_data filter hook which is called by the wp_insert_post function prior to inserting into or updating the database.

for example this will take the first term of each taxonomy and set them as the title:

function custom_post_type_title_filter( $data , $postarr )
  //check for your post type
  if ($postarr['post_type'] == 'your type name'){
    if (isset($_post['newtag'])){
        $artist = $album = $year = '';
        foreach($_post['newtag'] as $tax => $terms){
            if ($tax == "artist"){
                $artist = $terms[0];
            if ($tax == "album"){
                $album = $terms[0];
            if ($tax == "year"){
                $year = $terms[0];
        $data['post_title'] = $artist.' '.$album .' '. $year;
  return $data;

add_filter( 'wp_insert_post_data' , 'custom_post_type_title_filter' , '99' );

this assumes that your custom taxonomies are none hierarchical (like tags) and you will have to change to there right name as well as the custom post type name.

Hope this helps.

  • @Baininternet When I drop that in I'm getting a "Warning: Missing argument 2 for custom_post_type_title_filter() in xxx" error. Any thoughts on what's wrong? I'm not using hierarchical taxonomies.
    – MTT
    Apr 20, 2011 at 1:10
  • if you show the exact code you are using i could know better.
    – Bainternet
    Apr 20, 2011 at 8:09
  • @Baininternet Code is here: gist.github.com/931225
    – MTT
    Apr 20, 2011 at 12:56
  • just add 2 in your add_filter at the end so: add_filter( 'wp_insert_post_data' , 'custom_post_type_title_filter' , 99 ,2);
    – Bainternet
    May 18, 2011 at 18:02
  • @Bainternet I don't understand how your code changes the title of the feed? I am looking for sth related to the above problem (wordpress.stackexchange.com/questions/26535/…) and I was thinking that your code perhaps could help me out...
    – user2015
    Aug 22, 2011 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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