How to create a transient that persists the data for the whole duration of the expiration, even when object cache is enabled?

I eventually used a combination of update_option and WP Cron: // Create the option. update_option(‘foo’, ‘bar’, false); /** * Schedule it to be deleted one week from now. * * @param int Expiration timestamp * @param string Hook that will be invoked * @param string Params to send to the hook callback */ wp_schedule_single_event( time() … Read more

Homepage not loading correctly, only after refreshing

You can change your current theme to storefront and check whether the scripts and styles are properly enquequed. use this format to enqueque style and scripts and inspect the code for debugging class yourPluginName { public function __construct() { add_action(‘wp_enqueue_scripts’, array($this, ‘enqueue’)); } public function enqueue() { wp_enqueue_script(“jquery”); wp_enqueue_script(‘my-js’, plugins_url(‘/script.js’, __File__)); wp_enqueue_style(‘my-theme’, plugins_url(‘/style.css’, __File__)); }

Cache a number of responses from external json feeds?

$body = get_transient( ‘my_api_response_value’ ); if ( false === $body ) { $url=”https://api.myapi.com/chart?ticker=” . $ticker . ”; $response = wp_remote_get($url); if (200 !== wp_remote_retrieve_response_code($response)) { return; } $body = wp_remote_retrieve_body($response); set_transient( ‘my_api_response_value’, $body, 5*MINUTE_IN_SECONDS ); } $formatted_json = json_decode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); We submit a request at the beginning because the transient doesn’t … Read more

Keeping Objects in Memory

This is a perfect use case for Transients. In WordPress, transients are short-lived data objects. By default, they’re persisted to the database using WordPress’ built-in WP_Object_Cache object. However, you can use a variety of caching plugins (Batcache is an outstanding one that works with Memcached) to store Transients in memory. To set a transient, call … Read more