• Resolved yinxingmaiming

    (@yinxingmaiming)


    I’m really stuck on this. Trying to add (any) basic custom query to an Elementor Post widget.

    Issue – custom query is just ignored, widget displays all posts, regardless of custom query params.

    screenshot of post widget setup

    code snippet

    function custom_query_test_02 ( $query ) {
    $query_args = array(
            'post_status' => 'draft',
        );
        
        $query = new WP_Query( $query_args );
        return $query;
    }
    add_action( 'elementor/query/{$query_id}', 'custom_query_test_02' );

    I’ve tried:
    – adding code to functions.php and WPCode snippet
    – different filters
    – various syntax for setting $query (per Elementor Custom Filter doc

    Nothing works! No errors thrown, but it just ignores the custom query.`

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    Please send me a link to your site.

    Thread Starter yinxingmaiming

    (@yinxingmaiming)

    Thx for the quick reply. Not quite sure what you’re referring to.

    The page in question is: https://dev04.sinologix.io/

    I guess the more helpful angle would be: is there any known problem with custom queries?

    Thx

    Thread Starter yinxingmaiming

    (@yinxingmaiming)

    The Elementor doc references: {$query_id}, which I had assumed meant some auto-generated query id would be interpolated.

    But in fact, it needs a literal, as in:

    add_action( ‘elementor/query/xxxxxx’, ‘custom_query_test_02’ );

    For those of us not coming from a WP dev background, a suggestion would be to more clearly define the add_action param types.

    Good point @yinxingmaiming, and do you know where I can get that ID?

    Never mind, I found that in the Posts or Portfolio widgets, there is a field called “Query ID” where to put that custom ID to identify it later in the Hook.

    Anyway I needed to modify the WooCommerce widget via Hook or something similar, and this widget doesn’t have “Query ID”, but it can be modified using the filter “woocommerce_shortcode_products_query”, ex:

    add_filter( 'woocommerce_shortcode_products_query', function( $query_args, $attributes, $type) {
    	// modify the query args.
    	return $query_args;
    }, 10, 3);
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Query – not working’ is closed to new replies.