WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have custom plugin which registers multiple CPT's and i want to reuse the features of wp-posts-to-posts to define relationships. I'm just wondering what is the correct/best way to include the api.php file within my own plugin?

function my_connection_types() {

    require_once( ABSPATH . 'wp-content/plugins/posts-to-posts/core/api.php' );
    // Make sure the Posts 2 Posts plugin is active.
    if ( !function_exists( 'p2p_register_connection_type' ) )

    p2p_register_connection_type( array(
            'name' => 'events_to_races',
            'from' => 'event',
            'to' => 'race',
            'cardinality' => 'one-to-many'
    ) );
share|improve this question

closed as off-topic by Pieter Goosen, s_ha_dum Oct 15 '14 at 20:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

If the posts-to-posts plugin is running on your site, I am not sure you'd need to include api.php but of course that depends on how the plugin works making the question off-topic as dependent on third party code. – s_ha_dum Oct 15 '14 at 20:00
up vote 1 down vote accepted

Don't try to load the plugin yourself, check for its existence on your activation hook.

If it's not activated, throw an error; WordPress will display the message & prevent activation of your plugin.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.