Make WordPress Core

Opened 17 years ago

Closed 16 years ago

Last modified 16 years ago

#5746 closed enhancement (duplicate)

Add id of the post to the 'the_title' filter

Reported by: henrikmelin's profile henrikmelin Owned by: westi's profile westi
Milestone: Priority: normal
Severity: normal Version: 2.3.2
Component: General Keywords: 2nd-opinion has-patch
Focuses: Cc:

Description

When the id of a post is specified in get_the_title($id), it is not always possible to get the ID of the post in the 'the_title' filter, since the post is not necessarily held in $post. For a good example of this see the' Activity Box' on the Dashboard.

One reason one would want the id is to modify the title with, e.g. values held in custom fields.

I propose that the id is passed as an argument to the 'the_title' filter as follows:

function get_the_title($id = 0) {

...
return apply_filters( 'the_title', $title, $post->ID );

}

Which would always make the (correct) id available to the filter.

Cheers,
Henrik.

Attachments (1)

5746.diff (494 bytes) - added by DD32 17 years ago.
Make it so.

Download all attachments as: .zip

Change History (11)

#1 @lloydbudd
17 years ago

  • Milestone set to 2.6

@DD32
17 years ago

Make it so.

#2 @DD32
17 years ago

  • Keywords has-patch added
  • Milestone changed from 2.6 to 2.5

I can see that for some people, It'd be good to know which post title the filter is modifing, so i've made a patch.

#3 @Denis-de-Bernardy
17 years ago

Imho, the same could be said for the_content, the_excerpt, and other post-related filters.

Then again, get_the_ID() can return the ID while in the loop, and this is good enough as far as I can tell.

#4 @ffemtcj
17 years ago

  • Milestone changed from 2.5 to 2.6

#5 @DD32
17 years ago

Hm.. I've actually got a use for this now.. - I've got a the_title filter which is used to add a prefix to blog posts based on the categories of the post.

The issue is that when displaying the title outside of the loop, The filter function doesnt have a clue what post its supposed to be applying the filter to.

Places where its used outside of the loop include custom loops on the homepage, or in sublists within the blog page (Which is a place AFAIK, you do not want to have an extra loop to prevent mucking up its parent?)

#6 @westi
17 years ago

  • Owner changed from anonymous to westi
  • Status changed from new to assigned
  • Summary changed from Add id of the post to the 'the_post' filter to Add id of the post to the 'the_title' filter

I still need to do my filter review to stop the same filter name being used in multiple places.

Passing extra stuff with filters can't be a bad idea though.

#7 @DD32
17 years ago

I still need to do my filter review to stop the same filter name being used in multiple places.

Yep.. For example this use of the_title: http://trac.wordpress.org/browser/trunk/wp-includes/link-template.php#L607

Might be nice to standardise on that format then.

#8 @Denis-de-Bernardy
16 years ago

See dup: #9319 (suggests passing $post instead)

#9 @Denis-de-Bernardy
16 years ago

  • Milestone 2.9 deleted
  • Resolution set to duplicate
  • Status changed from assigned to closed

Closing as dup of #9666

#10 @ryan
16 years ago

(In [11112]) Pass post ID to the_title filter. Props DD32. see #5746 #9666

Note: See TracTickets for help on using tickets.