Method Reference

get_itemset_recommendations( $items, $number )

Description

The get_itemset_recommendations method returns a array of post IDs sorted by the relevance to the current items.

Item-set recommendations can be applied to the shopping cart, wishlists, watchlists, or any set of items that may go together. Some also call this “complimentary purchase” recommendations.

Usage

$recomendo->get_itemset_recommendations( $items, $number );

Parameters

$items

(array) (required)  Array containing the IDs of the Posts we are interested in finding complementary items to

Default: None

$number

(integer) (required) Number of recommendations to return.

Default: None

Return Values

(array) (false)

Recomendo returns an array with the following keys (or false if there was a connection error):

  • itemScores: Array containing the following keys:
    • item: the post ID
    • score: the relevance score (higher is better)

Examples

$items = [ 1094, 1123, 431 ];
$number = 12;
$response = $recomendo->get_itemset_recommendations( $items, $number );

// check the response from the Recomendo servers is not empty or no results
if ( $response != false and array_key_exists( 'itemScores', $response ) ) {
    
    // Loop over each recommendation	
    foreach ($response['itemScores'] as $i ) {
        
        // get the post 
        $post_object = get_post( $i['item'] );
	
        // Do whatever you need with the post 

    }
}

Exploring the contents of the $response array:

<?php print_r( $response['itemScores'] ); ?> 
 
Array ( [0] => Array ( [item] => 1068 [score] => 3.261805 ) [1] => Array ( [item] => 1212 [score] => 2.6814537 ) [2] => Array ( [item] => 999 [score] => 1.3862944 ) [3] => Array ( [item] => 1157 [score] => 1.3862944 ) [4] => Array ( [item] => 1308 [score] => 1.3862944 ) [5] => Array ( [item] => 2009 [score] => 1.2396909 ) [6] => Array ( [item] => 1315 [score] => 1.1451323 ) [7] => Array ( [item] => 2055 [score] => 1.1239301 ) ) Array ( [0] => Array ( [item] => 2081 [score] => 0 ) [1] => Array ( [item] => 1449 [score] => 0 ) [2] => Array ( [item] => 1016 [score] => 0 ) [3] => Array ( [item] => 353 [score] => 0 ) )