Skip to content

How to set custom frequency for MPG data fetch ​

The MPG plugin lets you control how frequently data updates are fetched. Despite its name, the Live option does not fetch data on every page request. Use the filter below to set a custom refresh interval, or trigger updates on demand with a webhook.

In this article

How to Change the Live Data Fetch Interval ​

To customize the interval for live data fetching, use the following filter:

add_filter('mpg_live_data_update_interval', function($time){
    return 60; // Set the time in seconds. In this example, it's 60 seconds (1 minute).
});

After adding this filter, clear the existing transients (cached data) or wait for them to expire for the new interval to take effect.

On-Demand Data Fetching with Webhooks ​

In addition to customizing the interval, MPG supports data fetching on demand through webhooks. The Sync frequency option lets you select On Demand mode, where you can trigger data updates via a Webhook URL (as seen in the screenshot below).

📝 Note: On Demand mode and the Webhook URL are Pro features and are only available in MPG Pro.

MPG Plugin Webhook URL Interface

Send a POST request to the webhook URL to fetch data whenever needed, without waiting for scheduled intervals. This is particularly useful when data updates are triggered by external actions or systems.

☝️ Keep in mind: If you see an MPG admin notice saying your webhook URLs have changed after an upgrade, open every project that uses On Demand sync, copy the currently shown Webhook URL, replace the old URL in the external service that sends the request, and test the new URL before dismissing the notice. If you do not see this notice, you do not need to replace your existing webhook URL.

Real Use Cases for Webhooks ​

  • Form Submission: Trigger data updates when a user submits a form on your website, ensuring the most recent data is available.
  • API Integration: Sync your MPG dataset with an external system or API that sends a webhook request each time data changes, ensuring real-time updates.
  • Spreadsheet Updates: If you're using a Google Sheet or external spreadsheet as a data source, you can trigger data refreshes by configuring the webhook to be called whenever the sheet is updated.

Testing Webhooks Using Postman ​

To test your webhook, use Postman, a tool for API testing:

  1. Download and install Postman from the official website.
  2. Open Postman and create a new POST request.
  3. Enter the Webhook URL from the MPG plugin as the request URL.
  4. Click Send to trigger the data fetch via the webhook.

FAQs ​

Q: Can I set the interval to less than 1 minute?

A: Yes, but setting it too low might increase server load. It is generally advisable to keep the interval at 1 minute or more, depending on your business needs.

Was this helpful?