PHP code example of 10up / wp-content-connect

1. Go to this page and download the library: Download 10up/wp-content-connect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

10up / wp-content-connect example snippets


function my_define_relationships( $registry ) {
    $args = array(
        'from' => array(
            'enable_ui' => true,
            'sortable' => true,
            'labels' => array(
                'name' => 'Related Tires',
            ),
        ),
        'to' => array(
            'enable_ui' => false,
            'sortable' => false,
            'labels' => array(
                'name' => 'Related Cars',
            ),
        ),
    );

    $relationship = $registry->define_post_to_post( 'car', 'tire', 'car-tires', $args );    
}
add_action( 'tenup-content-connect-init', 'my_define_relationships' );


function my_define_relationships( $registry ) {
    $args = array(
        'from' => array(
            'enable_ui' => true,
            'sortable' => false,
            'labels' => array(
                'name' => 'Related Users',
            ),
        ),
    )
    
    $relationship = $registry->define_post_to_user( 'post', 'related', $args );   
}
add_action( 'tenup-content-connect-init', 'my_define_relationships' );

$query = new WP_Query( array(
    'post_type' => 'post',
    'relationship_query' => array(
        'relation' => 'AND', // AND is default
        array(
            'related_to_post' => 25,
            'name' => 'related',
        ),
        array(
            'related_to_user' => 5,
            'name' => 'researcher',
        )
    ),
) );

'relationship_query' => array(
    array(
        'related_to_post' => 25,
        'name' => 'related',
    ),
),
'orderby' => 'relationship',

'relationship_query' => array(
    array(
        'related_to_post' => 25,
        'name' => 'related',
    ),
    array(
		'related_to_post' => 15,
		'name' => 'related',
	),
),
'orderby' => 'relationship',

$registry = \TenUp\ContentConnect\Plugin::instance()->get_registry();

// Gets the car to tire relationship defined in the example above
$relationship = $registry->get_post_to_post_relationship( 'car', 'tire', 'car-tires' );

$registry = \TenUp\ContentConnect\Plugin::instance()->get_registry();

// Gets the post to user relationship defined in the example above
$relationship = $registry->get_post_to_user_relationship( 'post', 'related' );

// $relationship is the return value from ->define_post_to_post()
$relationship->add_relationship( 1, 2 ); // Adds a relationship between post ID 1 and post ID 2

// $relationship is the return value from ->define_post_to_post()
// Note that the example above added these in the reverse order, but the relationship is still deleted
$relationship->delete_relationship( 2, 1 ); // Deletes the relationship between post ID 1 and post ID 2. 

// $relationship is the return value from ->define_post_to_post()
$relationship->replace_relationships( 5, array( 2, 3, 6, 7, 8 ) );

// $relationship is the return value from ->define_post_to_post()
$relationship->save_sort_data( 5, array( 7, 6, 3, 8, 2 ) );

// $relationship is the return value from ->define_post_to_user()
$relationship->add_relationship( 1, 5 ); // Adds a relationship between post 1 and user 5

// $relationship is the return value from ->define_post_to_user()
$relationship->delete_relationship( 1, 5 ); // Deletes the relationship between post 1 and user 5

// $relationship is the return value from ->define_post_to_user()
$relationship->replace_post_to_user_relationships( 5, array( 3, 4, 5 ) );

// $relationship is the return value from ->define_post_to_user()
$relationship->replace_user_to_post_relationships( 2, array( 6, 7, 8 ) );

// $relationship is the return value from ->define_post_to_user()
$relationship->save_post_to_user_sort_data( 5, array( 2, 4, 1, 6, 3 ) );

// $relationship is the return value from ->define_post_to_user()
$relationship->save_user_to_post_sort_data( 1, array( 4, 2, 7, 9, 8 ) );