Add custom fields to p2p admin box using p2p_candidate_title
-
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)
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.