Title_save_pre – Simple problem that u know for sure

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:

Read More
<?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

Related posts

Leave a Reply

1 comment

  1. 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');
        ?>