Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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