[wp-hackers] CPT with post_title names
Simon Blackbourn
piemanek at gmail.com
Tue Aug 16 21:29:04 UTC 2011
I had a very similar scenario to you and came up with this solution:
- The post title consists of the member's name written in the standard
firstname surname way, minus the honourific.
- I hook into the enter_title_here filter so the title input placeholder
text reads "Enter first name and surname here", just as a reminder for the
site editor.
- There is a metabox on the post edit screen for the honourific, selected
from a dropdown.
- A postmeta called alphaname is auto-generated from the title on the
save_post hook as follows:
$names = explode( ' ', trim( $_POST['post_title'] ) );
$words = count( $names );
$alphaname = $names[$words-1] . ' ' . $names[0];
Note: doesn't work for Cher or Madonna ;-)
- The posts_join, posts_orderby and posts_where filters are used to sort
posts by the alphaname postmeta.
- The honourific, if one exists, is output before the post title.
There are doubtless more elegant ways, but that has worked well for over a
year now with no mishaps on a site managed by non-teccie users.
Hope that helps
Simon
More information about the wp-hackers
mailing list