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 two custom post type. Then I need to use title_save_pre to post title prior to saving it in the database. I need to use this filter just for one custom post type.

This is my function:

<?php
function muda_titulo() {
global $post;
$type = get_post_type($post->ID);
if ($type== 'event') {
$title = $post->post_excerpt;
$day= get_the_time('l, d F, Y');
return $title.' - '.$day;

} else if ($type == 'post') {
// do nothing 
}
}
add_filter ('title_save_pre','muda_titulo');
?>

On custom post type 'event' it works fine, but on custom post type 'post' the title changed to a white space.

Thank u

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Try the code below. Filter's take a value and returns it afterwards.

  <?php
    function muda_titulo($title) {
    global $post;
    $type = get_post_type($post->ID);
    if ($type== 'event') {
    $title = $post->post_excerpt;
    $day= get_the_time('l, d F, Y');
    return $title.' - '.$day;

    } else if ($type == 'post') {
       return $title;
    }
    }
    add_filter ('title_save_pre','muda_titulo');
    ?>
share|improve this answer
    
Worked. Nice catch =) Thanks m8 :) –  Sergio Soares Jan 26 '11 at 15:14
    
Hi, I used some of your code here to help me fix a problem I was having trying to convert a Taxonomy Term into a post title for a specific post. However it is not effecting the permalink when it applies the filter. Any help you could give would be great -- and thanks for the code as well, gave ya an upvote! wordpress.stackexchange.com/questions/22537/… –  Duiwel Jul 10 '11 at 22:19

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.