Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
@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. –  mattrepublic Apr 20 '11 at 1:10
    
if you show the exact code you are using i could know better. –  Bainternet Apr 20 '11 at 8:09
    
@Baininternet Code is here: gist.github.com/931225 –  mattrepublic Apr 20 '11 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 '11 at 18:02
    
Thank you! –  mattrepublic May 19 '11 at 14:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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