How to use Custom Query ID in Post Widgets using Element Pack Pro?

  • BdThemes
  • How to use Custom Query ID in Post Widgets using Element Pack Pro?

Table Of Contents

How to use Custom Query ID in Post Widgets using Element Pack Pro?

The native Query system build for Post widgets by Element Pack provides powerful solutions to sort out your posts to appear systematically according to your preferences. But still, you might want a Custom Query feature to customize the Query to apply your personalized filters.

To do that, Element Pack offers a Custom Query ID field within the Post widgets to give you the freedom of customization.

Let’s explore how you can take advantage of query customization.

1. Find Custom Query ID Field Inside Post Widgets

The native Query feature is available for all posts, portfolios, testimonials, and such post-type widgets. If you visit the Element Pack website and click on the Elements Demo menu, you will see a category filter named Post / Query inside the list, which sorts out all post-type widgets from Element Pack.

custom query id

Now, open any page using the Elementor website editor and drag-drop a post widget (i.e. Post Slider by Element Pack) inside the page.

There, you can find the Custom Query ID field inside the Query section under the content tab.

Simply go to Content > Query > Query ID

Custom Query ss1 - BdThemes

You have to insert a query ID inside the field to make it functional over the post widget.

The Query path follows Element Pack’s native system: element_pack/query/my_query_id

here, my_query_id is a custom name for the query, and the name can be anything you want it to be.

2. Set Up Custom Query in WordPress

To setup a custom query in WordPress, you need to use a custom hook and a couple of lines of code.

Please follow these steps:-

  1. Go to WordPress Dashboard > Appearance > Theme File Editor > Open Functions.php file
  2. Scroll down and paste the custom hook code at the bottom.
add_action( 'element_pack/query/query_id', function( $query ) {
    // Do what you want to do
});

Custom Query Examples

1. Using the hook, you can create custom queries to filter-out posts by post IDs like this-

// Exclude single posts by ID
add_action( 'element_pack/query/query_id', function( $query ) {
    $query->set( 'post__not_in', array( 7, 11 ) );
});

2. You can create date filters to show posts only within a certain time frame-

// Get between post, 2015 - 2023
add_action( 'element_pack/query/query_id', function( $query ) {
    $query->set('date_query', array(
        array(
            'after'  => array(
                'year'   => 2015,
                'month'  => 01,
                'day'    => 01,
            ),
            'before'     => array(
                'year'   => 2023,
                'month'  => 01,
                'day'    => 01,
            ),
            'inclusive'  => true,
        )
    ));
});

Following the examples, you can create many different custom queries to satisfy your needs.

Please find guidelines on Query customizations by WordPress Dev.

Take advantage of fine-tuned plugins

Get Customizable Elementor Widgets to Power Up Your Website

Take advantage of fine-tuned plugins to speed up web projects without sacrificing quality. We offer a 14-days money-back guarantee.
BdThemes is the sole owner of #1 market-leading addons for Elementor such as Element Pack Pro, Prime Slider, Ultimate Post Kit, Ultimate Store Kit, Pixel Gallery, and more useful plugins. This website is powered by Element Pack Pro and Rooten Theme.
Need any further assistance? Call Us:+880 1700 55 95 95
Our supported payment system and security badge