Support » Plugin: Posts 2 Posts » Connection metadata field types

  • Hey! First – thanks for a great plugin – it really is – great!:)

    Have a question about connection meta fields. Is it possible to make a field type where you can add/search custom posts (similar to creating a connection form).. Something like:
    ‘role’ => array(
    ‘title’ => ‘Role’,
    ‘type’ => ‘custom_post’,
    ‘value’ => ‘custom_post_name’ )
    … and store a post ID into p2pmeta db table.
    Maybe you can give me some hints how to do it..? would be super.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think you need to elaborate on what you’re trying to achieve.

    At face value you don’t need connection metadata, you just need to create a “normal” connection where either the “from” or “to” value is custom_post_name.


    When you say custom_post, you mean a list of certain posts not a post type?

    Anyway, here is an example where I populated a dropdown with custom values, as that is what it seems that you want to do (for some reason).

    Instead of using $product_category_terms = get_terms(‘product_category’, $args) you could use a WP post query, get the posts you like included and then they will show up in the dropdown. But it’s a simple dropdown, not a fancy search field.

    function my_connection_types() {
    	$args = array(
    		'hide_empty'    => false,
    		'fields'        => 'names'
    	$product_category_terms = get_terms('product_category', $args);
        p2p_register_connection_type( array(
            'name' => 'products_to_projects',
            'from' => 'product',
            'to' => 'project',
    		'fields' => array( // this creates extra meta fields that can be added to a connection - use to distinguish between connections by meta
    					'product_type' => array(
    						'title' => 'Product Type',
    						'type' => 'select',
    						'values' => $product_category_terms
    					'count' => array(
    						'title' => 'Count',
    						'type' => 'text',
    					'role' => array(
    						'title' => 'Role',
    						'type' => 'select',
    						'values' => array( 'engineer', 'support', 'manager' )
        ) );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Connection metadata field types’ is closed to new replies.