Divi is a WordPress theme and page builder by Elegant Themes that provides a visual drag-and-drop interface for creating website layouts. The Divi Blog Module, Post Slider, and Portfolio modules allow you to display posts with customizable layouts, but do not include a built-in option for sorting by view count.
Post Views Counter Pro integrates with Divi to enable ordering posts by view count in these modules. The integration is implemented in includes/integrations/divi.php and activates automatically when both Post Views Counter Pro and Divi are active on your site.
How It Works
The Divi integration enables sorting by post views through a CSS class trigger mechanism. When you add the CSS class orderby-post-views to a supported Divi module, the integration:
- Detects the class on the module instance during rendering
- Intercepts the module’s query using a
pre_get_postshook - Sets the query to order by post views:
$query->query_vars['orderby'] = 'post_views' - Marks the query with
$query->pvc_orderby = truefor internal tracking - Cleans up the temporary query modification after the module renders
This approach ensures ordering applies only to the specific module with the CSS class, not globally across your site.
Supported Modules
Sorting by post views is supported for these Divi modules:
- Blog module (
et_pb_blog) - Post Slider module (
et_pb_post_slider) - Portfolio module (
et_pb_portfolio)
Other Divi modules do not support ordering by views through this integration.
Setup
Prerequisites
- Post Views Counter Pro installed and activated
- Divi theme or Divi Builder plugin installed and activated
Enable the Integration
- Navigate to Post Views > Integrations
- Locate the Divi integration option
- Enable the integration toggle
- Save changes
The integration initializes automatically when both plugins are active.
Add the CSS Class to a Module
To sort a supported Divi module by post views:
- Open your page in the Divi Builder
- Add or edit a Blog, Post Slider, or Portfolio module
- Open the module settings panel
- Navigate to Advanced > CSS ID & Classes
- In the CSS class field, enter:
orderby-post-views - Save the module and update the page

The module will display posts ordered by view count (highest first). The CSS class is case-sensitive and must be entered exactly as shown.
Configuration
Module Settings Compatibility
After adding the CSS class, the module continues to accept all standard content settings:
- Post Type selection
- Post Count / posts per page
- Included / Excluded Categories
- Other display options specific to each module
The ordering by views works alongside these settings without conflict.
Displaying View Counts in Divi Layouts
To display view counts within Divi layouts, use the [post-views] shortcode:
- Open a page or template in the Divi Builder
- Add a Code or Text module where you want the view count to appear
- Insert the
[post-views]shortcode - Configure shortcode parameters as needed
- Save the module and publish your layout
Ensure your post types are enabled for tracking at Post Views > Counting > Tracking Targets.
Counter Mode Compatibility
The Divi integration works with all counter modes: PHP Mode, JavaScript Mode, and REST API Mode. No specific counter mode is required for Divi compatibility. Choose your counter mode based on your site’s caching configuration and tracking requirements.
If you experience counting issues with cached pages, review your caching compatibility settings at Post Views > Counting > Performance & Caching.
Troubleshooting
Posts Not Sorting by Views
Symptoms: Divi module displays posts but the order does not reflect view counts.
Solutions:
- Verify the CSS class is entered exactly as
orderby-post-views(case-sensitive, no spaces or typos) - Confirm you are using a supported module: Blog, Post Slider, or Portfolio
- Check that posts have recorded views by viewing individual posts and checking counts in the WordPress admin
- Clear any page caching and Divi’s static CSS cache, then reload the page
View Counts Not Displaying
Symptoms: The [post-views] shortcode shows no output or appears as plain text.
Solutions:
- Ensure the Divi integration is enabled at Post Views > Integrations
- Use a module that processes shortcodes (Code or Text module)
- Verify the post type is enabled for tracking at Post Views > Counting > Tracking Targets
- Check visitor exclusion settings at Post Views > Counting > Visitor Exclusions to confirm your user role or IP is not excluded from tracking
Counts Not Incrementing
Symptoms: Views are not being counted for pages built with Divi.
Solutions:
- Review counter mode settings at Post Views > Counting > Tracking Behavior
- If using a caching plugin, verify caching compatibility at Post Views > Counting > Performance & Caching
- Ensure tracking is enabled for the post types displayed in your Divi layouts
Integration Not Appearing
Symptoms: Divi integration option is not visible in the Integrations tab.
Solutions:
- Confirm Divi theme or Divi Builder plugin is installed and active
- Verify you are using Post Views Counter Pro (this integration is not available in Lite)
- Check for plugin conflicts by temporarily deactivating other plugins
Wrong Module Type
Symptoms: CSS class is added but posts do not sort by views.
Solutions:
- Verify you are using Blog, Post Slider, or Portfolio module specifically
- Other Divi modules (such as the Blog Grid module or custom post type modules) do not support this integration
- The CSS class
orderby-post-viewshas no effect on unsupported module types
