0

How can I filter the Elementor Posts widget with a custom php query that returns posts with a specific tag attached?

I want to do something similar to this:

function my_query_by_post_types( $query ) {
    $query->set( 'post_type', [ 'custom-post-type1', 'custom-post-type2' ] );
}
add_action( 'elementor/query/{$query_id}', 'my_query_by_post_types' );

The line that interests me is:

$query->set( 'post_type', [ 'custom-post-type1', 'custom-post-type2' ] );

But instead of querying post types, I want to query a specific Tag from the "Posts" post type. I'm not familiar with the syntax so I am not sure how to type it in.

6
  • 1
    for help with Elementor you should ask in an Elementor community or their official support routes, Elementor dev support questions are off topic here and not in this stacks scope, as are dev support questions for other 3rd party plugins
    – Tom J Nowell
    Commented Jul 25, 2022 at 15:30
  • My question had to do with the WP_Query, Elementor was just filler. I did not request for plugin support.
    – ChristosDg
    Commented Jul 25, 2022 at 16:22
  • 1
    You're asking for help with an Elementor filter so that you can modify an Elementor widget. It is impossible to answer without Elementor knowledge. elementor/query/{$query_id} is not a WP filter, and the Elementor posts widget is unique to Elementor. This is an Elementor question. If we pretend this is a pre_get_posts Q as the code implies (which it is not), that is no guarantee it will do what you need it to do either as it's not an equivalent for the recent posts widget. This is an inappropriate place to ask this question, and this is not a place to get help with Elementor.
    – Tom J Nowell
    Commented Jul 25, 2022 at 16:25
  • 1
    It goes beyond the scope of Elementor Support so this is why I asked it here. I'm certain there are people that are familiar with Elementor custom queries so this is why I asked it. Reference the TOS section where what I posted is forbidden please.
    – ChristosDg
    Commented Jul 25, 2022 at 16:30
  • It cannot be answered without Elementor expertise and knowledge, it is offtopic, this is not an appropriate place for this question. Neither will arguing your way to getting it opened, that's not how you bring a question back on topic. I'm going to lock comments now as this is counterproductive. If you can edit your question to not reference Elementor and bring it back on topic please do so, but I believe it will not be the same question if you do that. If any Elementor knowledge is required no matter how small then it is offtopic as it's a 3rd party plugin dev support question.
    – Tom J Nowell
    Commented Jul 26, 2022 at 10:36

0