Okay
  Public Ticket #2179099
Request for functionality Custom query filter
Closed

Comments

  • Siv Hansen started the conversation

    In Elementor Pro, the post widget has the option of setting a custom query filter

    71895262_10162453664370581_7465328629954641920_n.jpg?_nc_cat=111&_nc_oc=AQlhcSvztnlFpiZgwYeokm3duyfmzrTHu_HtVWx4JOXt0fBd6ADEQR7BqEnz5ZIPny4&_nc_ht=scontent.fosl2-1.fna&oh=b8612a0cf505dad186693d98122e4d99&oe=5E360CEA


    Then I can add code in my functions.php to retrieve whatever posts/pages/taxonomies specified in my custom query. In my case, this is what I use:

    /** the elementor/query/ part of the add_action is always present. The next part is the name of my custom query filter, as provided in the Query ID (screen dump) and then the function where I set the query using native WP query.

    add_action( 'elementor/query/park_related_by_taxonomy', 'pixlweb_related_posts' );

    function pixlweb_related_posts( $query ) {

    $post = get_queried_object();

    $post_tags = get_the_tags($post->ID);

    $t = array();

    foreach($post_tags as $tags){

    $t[] = $tags->name;

    }

    $params = array(

    'post_type' => 'parkexperience',

    'tax_query' => array(

    array(

    'taxonomy' => 'post_tag',

    'field' => 'slug',

    'terms' => $t,

    ),

    ),

    );

    $query->set( 'tax_query', $params );

    }


  •   Max replied privately