How to make custom post type feed title = taxonomies?

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?

Related posts

Leave a Reply

1 comment

  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];
                    continue;
                }
                if ($tax == "album"){
                    $album = $terms[0];
                    continue;
                }
                if ($tax == "year"){
                    $year = $terms[0];
                    continue;
                }
            }
            $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.