Method Reference

get_trending_items( $number )

Description

The get_trending_items method returns a array of post IDs sorted by popularity.

Usage

$recomendo->get_trending_items( $number );

Parameters

$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

$number = 12;
$response = $recomendo->get_trending_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 ) )