Custom Query Listing Widget Tutorial

We have Custom Query Option in Grid Post Listing, Magazine Listing, Slide Post Listing and Smart Listing Widget

Follow Below Formate

Samle 1- Multiple Post Type

function ec_custom_query_function($query_args) {
    // Define additional query parameters
    $extra_query = array(
        // Query for posts of specific post types
        'post_type' => array('post', 'page', 'custom_post_type'), // Add your custom post types here
        
    );

    // Merge the additional query with the original arguments
    $query_args = array_merge($query_args, $extra_query);

    return $query_args;
}

// Hook into a custom filter for flexibility
add_filter('ec_custom_query_id', 'ec_custom_query_function');

Sample 2 – Meta & Taxonomy query

function ec_custom_query_function($query_args) {
    // Define additional query parameters
    $extra_query = array(
        
        // Meta query (for custom fields)
        'meta_query' => array(
            array(
                'key' => 'custom_field_key',
                'value' => 'custom_value',
                'compare' => '='
            )
        ),

        // Taxonomy query (for custom taxonomies)
        'tax_query' => array(
            'relation' => 'OR',
            array(
                'taxonomy' => 'custom_taxonomy',
                'field' => 'slug',
                'terms' => array('term1', 'term2'),
            ),
            array(
                'taxonomy' => 'another_taxonomy',
                'field' => 'id',
                'terms' => 123, // Example term ID
            )
        )
    );

    // Merge the additional query with the original arguments
    $query_args = array_merge($query_args, $extra_query);

    return $query_args;
}

// Hook into a custom filter for flexibility
add_filter('ec_custom_query_id', 'ec_custom_query_function');