WordPress.org

Forums

Posts 2 Posts
Connection metadata field types (3 posts)

  1. raifs
    Member
    Posted 1 year ago #

    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.
    Thanks!

    http://wordpress.org/plugins/posts-to-posts/

  2. tedinoz
    Member
    Posted 1 year ago #

    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.

    Ted

  3. landwire
    Member
    Posted 1 year ago #

    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' )
    					),*/
    				),
        ) );

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic