Title: Programtically create connection
Last modified: August 22, 2016

---

# Programtically create connection

 *  [Lee Cloete](https://wordpress.org/support/users/leemustard/)
 * (@leemustard)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/programtically-create-connection-1/)
 * Hey Guys, Very cool plugin, juts one question,
 * I need some direction with regards to your plugin.
 * How, Would i programmatically create a connection between posts or post types(
   obviously with some parameters so it knows which posts to assign and “join”)
 * I’ve checked on the documentation and there is some direction, But i really don’t
   know how to apply it. Here
 * So basically, when you create a post & its assigned to certain taxonomy, The 
   post will automatically be be grouped with the connection type (which you define
   in functions file)
 * Is this possible?
 * Bests
    Lee
 * [https://wordpress.org/plugins/posts-to-posts/](https://wordpress.org/plugins/posts-to-posts/)

Viewing 1 replies (of 1 total)

 *  [John](https://wordpress.org/support/users/jsing/)
 * (@jsing)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/programtically-create-connection-1/#post-5780054)
 * For connecting posts programmatically you just need to gather both post ids:
 * `p2p_type( 'dogs_to_cats' )->connect( $first_post_id, $second_post_id, array('
   date' => current_time('mysql')) );`
 * For adding a taxonomy term at the same time:
 * `wp_set_post_terms( $first_post_id, 'Term', 'your_taxonomy', true );`

Viewing 1 replies (of 1 total)

The topic ‘Programtically create connection’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [John](https://wordpress.org/support/users/jsing/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/programtically-create-connection-1/#post-5780054)
 * Status: not resolved