Custom Sorting for Post-Based Modules

Learn about the default sorting option and custom sorting of posts in the Slider Revolution post-based modules.

Posts Sorting in Post-Based Modules

In Slider Revolution [?] Slider Revolution is a website content creation tool with a focus on captivating animation and stunning visual effects.

It began its life as a plugin for creating slideshows, but has evolved into a fully fledged piece of design software.
, a post-based slider allows you to create modules [?] A module in Slider Revolution acts as a container for slides, which in turn act as containers for layers. Modules are created and edited with the module editor.

A "module" is a single, self contained piece of content. You can think of this as being similar to the way a post or page in regular WordPress is a self contained piece of content.

A module can represent any kind of content Slider Revolution is capable of creating, such as a slider, carousel, hero unit, navigation menu, posts display and so on.

Multiple modules can be combined to form rich content such as complete sites and landing pages.
that pull content from your WordPress posts automatically. Instead of manually designing each slide, you define the post-selection criteria.

Slider Revolution populates the slides with elements like featured images, titles, and excerpts from those chosen posts. This is a great way to showcase your latest blog posts, products, or any other post on your website.

Post sorting refers to arranging your website’s content (posts, products, etc.) in a specific order. Posts display chronologically (newest first) by default, but sorting allows you to customize this.

You can achieve this through plugins for drag-and-drop reordering, custom code for specific criteria, or built-in theme features (if available). Sorting your posts helps you prioritize content and improve user experience by first displaying what’s most relevant.

Module Default Sorting Options

The Slider Revolution plugin’s post-based module has some default sorting options available. For example:

  • Post ID: Sort by the unique ID assigned to each post.
  • Date: Sort by the post’s Published date.
  • Title: Sort posts alphabetically by their titles.
  • Slug: Sort posts alphabetically by their assigned slugs.
  • Author: Sort posts alphabetically by Author Name.
  • Last Modified: Sort posts based on when they were most recently published or updated.
  • Number of Comments: Sort posts based on which contains the most comments.
  • Random: Sort posts randomly each time the slider is viewed.
  • Unsorted: No order specified.
  • Custom Order: Sort posts or pages with the “menu_order” option, which allows users to specify a custom order for each post or page.

Note: The Custom Order differs from Custom Sorting (which we will discuss in this article).

What is Custom Sorting?

Slider Revolution offers custom sorting for post-based sliders, giving you more control over how your content appears. This goes beyond the default options like date or title. With custom sorting, you can leverage custom meta values – unique data points you define for your posts.

The provided code snippet (in the Sort Posts by Custom Meta section) allows you to modify the built-in WordPress query used by Slider Revolution, sorting posts based on these custom meta values. This unlocks a powerful way to showcase your content in a way that best suits your needs.

Let’s create a custom meta.

Create a Post Custom Meta

Enable Custom Field Panel

Go to the Posts tab from the left in the WordPress dashboard:

Go to the post of your choice:

From the top right corner, click on the vertical three dots to open the Options dropdown menu:

Select the Preferences option:

A popup of preferences settings will appear:

Go to the Panels tab:

Toggle the Custom fields option to on:

Click the Show & Reload Page button:

The Custom Fields panel will appear at the bottom:

Create a Custom Meta

Head over to the Add New Custom Field section under the Custom Field panel:

Click the Enter new button:

Type any name for the custom meta:

Add value for the custom meta value can be any of these: Numeric, Character, Date, Time, Date-Time:

Click the Update button from the top-right corner:

Copy the name of the custom meta; we will use it in the Add Code to Functions File section:

Sort Posts by Custom Meta

This section will modify Slider Revolution’s default WP_Query to sort posts using custom meta values.

Download and Install a File Manager Plugin

Go to the Plugins tab from the left-hand sidebar on the WordPress dashboard:

Click the Add New Plugin button from the top:

Search for File Manager plugin:

Locate the File Manager plugin by mndpsingh287 author.
Note: This is our choice as this is one of the popular plugins, but you can choose any File Manager plugin:

Click the Install Now button:

Click the Activate button:

Create a Backup of the Functions File

Go to the WP File Manager tab from the left-hand sidebar on the WordPress dashboard:

Go to the wp-content folder in your website’s file directory:

Double-click on the themes folder:

Go to the folder with the name of your theme on it:

Select the functions.php file:

Right-click on the file to open the options menu:

Click on the Download option:

Add Code to Functions File

Select the functions.php file:

Right-click on the file to open the options menu:

Select the Code Editor option; the editor will open in a popup window:

In the editor panel, scroll down to the end of the file:

At the bottom of the file, you can paste the code below:

/**
 * Modify Slider Revolution post sorting by Custom Meta
 */

function modify_post_order($query, $slider_id) {

    // Only replace 4 with your module’s numeric ID.
    if($slider_id == 4) {

        // Only replace the meta-custom-date with your meta key name.
        $query['meta_key'] = 'meta-custom-date';

        // Only replace the meta-custom-date with your meta key name.
        $query['orderby'] = 'meta-custom-date';

        // Sort post based on value types:
        // 'NUMERIC', 'CHAR', 'DATE', 'DATETIME', 'TIME'
        // Only replace ‘DATE’.
        $query['meta_type'] = 'DATE';

    }

    return $query;

}

add_filter('revslider_get_posts', 'modify_post_order', 10, 2);

Click the SAVE & CLOSE button:

Modify Code

In this section, we will review the code and make the necessary changes, such as module ID and custom meta name, which will differ for everyone.

Find Module ID

Go to the Slider Revolution dashboard:

Hover over a post-based module of your choice:

Click the pencil icon to edit the module:

Go to the CSS/jQuery subsection:

A popup CSS/JS Editor will appear:

Click on the API panel bar appearing at the right-hand side of the popup:

Click on a (+) icon button against any method:

This will add a method with your module ID in the editor panel of the popup:

Copy the numeric ID:

Remove the whole method from the editor:

Click the cross (X) icon from the top-right corner of the popup:

Replace Module ID

Go to the custom code added to the functions.php file:

Replace the numeric digit “4” from the code with the copied numeric ID:

Click the SAVE & CLOSE button:

Find & Replace Meta Key Name

Now, we will use the copied meta name from the Create a Custom Meta section:

Go to the custom code added to the functions.php file:

Locate the meta-custom-date in the added code:

Replace the meta-custom-date with your meta name for both meta_key & orderby:

Click the SAVE button:

Add a Meta Type:

In the following line, we have meta_type configured to DATE. You do not have to change it if you have added the date value in the Create a Custom Meta section:

Otherwise, you can change the only DATE to the meta type you have added as value. Here are the meta types: 

  • NUMERIC: Only for numeric values.
  • CHAR: Only for character values.
  • DATE: Only for date values.
  • DATETIME: For both date and time values.
  • TIME: Only for time values.

Click the SAVE & CLOSE button:

Contact Us

If you have any further questions or need additional assistance, you can contact us via support ticket or email ([email protected]); we’re here to help.

Custom Sorting for Post-Based Modules

The Author

Kashif Ahmed

Living by the motto "Be the reason someone smiles today."

If you have any questions or concerns, feel free to reach out to me directly at [email protected].

Liked this Post?
Please Share it!

Leave a Reply

Your email address will not be published. Required fields are marked *