• Resolved owenwalz

    (@owenwalz)


    Hi Scribu,

    I’ve added a snippet of code to my functions that pulls the title for custom post type ‘person’ from a combination of their first and last names (meta values). Unfortunately this filter seems to be confusing the p2p meta boxes. In the edit post screen they now show all connected posts with the same name of the post currently open for editing. The snippet I’m using is:

    function theme_slug_filter_the_title( $title ) {
        global $post;
        if ( 'person' == get_post_type( $post ) ) {
        	$custom = ( get_post_custom( $post->ID ) ? get_post_custom( $post->ID ) : false );
        	$custom_title = ( isset( $custom['person_name_first'][0] ) && isset( $custom['person_name_last'][0] ) ? $custom['person_name_first'][0]  . " " . $custom['person_name_last'][0]: '(No Name)' );
        	return $custom_title;
       	} else {
            return $title;
        }
    }
    add_filter( 'the_title', 'theme_slug_filter_the_title' );

    Is there a way I should modify this to make it more compatible with p2p?

    Thanks,
    O

    https://www.ads-software.com/extend/plugins/posts-to-posts/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author scribu

    (@scribu)

    The problem is that you’re using the $post global, instead of using the post id passed to the ‘the_title’ filter:

    function theme_slug_filter_the_title( $title, $post_id ) {
        $post = get_post( $post_id );
    
        if ( 'person' == get_post_type( $post ) ) {
        ...
    }
    add_filter( 'the_title', 'theme_slug_filter_the_title', 10, 2 );
    Thread Starter owenwalz

    (@owenwalz)

    Thanks so much. That worked perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Posts 2 Posts] Conflict with plugin filtering the_title()’ is closed to new replies.