Display Products section using an external API


I need to display the below sections in WordPress website using another API:

  1. Products search
  2. Products listing with pagination
  3. Popular products
  4. Stores section
  5. Categories and sub-categories section
  6. Similar Products

We have around 5 pages related to this section.

I am planning to implement this with ajax, wp_remote_get(), and TLC transients.

a) We have to display a large amount of data on the website. So it will add transients (a large amount of data) to the options table. Will this affect site performance?

b) Should we use any transient cleaners to remove the expired TLC transients?

c) Changing the limit in the API URL will not reflect in the transient data even after the expired time. Will this take time? Is this a known issue?

function test_tlc_transient() {
    $t = tlc_transient( 'popular-products' )
        ->expires_in( 300 )
        ->updates_with( 'sample_fetch_and_append', array( 'http://siteurl/restapi/frontend/GetMostProductViewed?start=0&limit=12' ) )
    var_dump( $t );
    if ( !$t )
        echo "The request is false, because it isn't yet in the cache. It'll be there in about 10 seconds. Keep refreshing!";
function sample_fetch_and_append( $url ) { 
    $f  = wp_remote_retrieve_body( wp_remote_get( $url, array( 'timeout' => 30 ) ) ); 
    return $f;

d) Do we have any better alternatives to implement this?


chithra 2 years 2020-10-23T05:10:20-05:00 0 Answers 13 views 0

Leave an answer