1

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

3

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');
    ?>
  • 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/… – Sam K Jul 10 '11 at 22:19

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.