Support » Plugins » Add custom fields to p2p admin box using p2p_candidate_title

  • Resolved userx19

    (@userx19)


    I’ve been trying to add custom fields or additional meta data next to the candidate connection title.

    function append_author_to_candidate_title( $title, $post, $ctype ) {
    	if ( 'subdishes_to_groceries' == $ctype->name && 'subdishes' == $post->post_type ) {
    
    		$title .= "ANYTHING";
    	}
    	return $title;
    }
    add_filter( 'p2p_candidate_title', 'append_author_to_candidate_title', 10, 3 );

    Even with a static value, I get nothing. I’ve added this code to my functions.php.

    I’ve also tried using custom fields with the default_cb key but even that does not seem to work. Please see following code:

    p2p_register_connection_type( array(
        'name' => 'subdishes_to_groceries',
        'from' => 'subdishes',
        'to' => 'groceries',
        'title' => 'Sub Ingredients',
        'admin_box' => array(
            'context' => 'normal'
        ),
        'fields' => array(
            'yield_unit' => array(
                'title' => 'Y Unit',
                'type' => 'text',
                'default_cb' => 'get_groc_y_unit', // CALLBACK
            ),
            'yield_price' => array(
                'title' => 'Y Price',
                'type' => 'text',
                'default' => 'asdasdasd',
            ),
            )       
    
    ) );    
    
    function get_groc_y_unit( $connection, $direction ) {
    
        global $post;
        $key = ( 'from' == $direction ) ? 'p2p_to' : 'p2p_from';
        $post = get_post( $connection->$key );
        setup_postdata($post);
    
        return the_title();
    
    }

    Am I missing anything, can anyone help please?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter userx19

    (@userx19)

    Ok, ‘p2p_connected_title’ is what I needed to use. Issue resolved. To customize it further, I decided to hack the core files and create custom columns with callback functions! Thanks Scribu, for the awesome plugin!

    Thread Starter userx19

    (@userx19)

    Also, ‘default_cb’ only works when creating a connection and not when existing connections are loaded in admin pages.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add custom fields to p2p admin box using p2p_candidate_title’ is closed to new replies.