Solved: Snippet with a little php code to create a Query ID that uses Get to pull in the variable value. My button refreshes the page and sets the category value.
Hi Les, I have been trying to do the same. In my case I have pages that are dynamically generated, and include a number of URL variables. One of those variables the the category that the Posts Widget should use to filter out my posts.
Elementor does not support this capability natively, so I was wondering how your code snippet looks to set the category for the posts widget. Can you please share what you came up with?
Regards,
Dan
Hi Dan, Here is the code I use in the code snippet. The name Leslie2 is the Query ID in the post display widget. The variable is animal.
Go to this page and select an animal and you will go to a Dynamic created template that just changes to show the different animal groups. 1 page shows all the different animal groups depending on the URL variable value that was set in the link.
https://tigercat721.pawsinthewoodlands.com/querybase/
// Showing multiple post types in Posts Widget
add_action( 'elementor/query/leslie2', function( $query ) {
// Here we set the query to fetch posts with
// post type of 'custom-post-type1' and 'custom-post-type2'
$c = htmlspecialchars($_GET["animal"]);
if ( $c == "dogs" ) {
$query->set( 'category_name' , 'dogs');
}
if ( $c == "cats" ) {
$query->set( 'category_name' , 'cats');
}
if ( $c == "turtles" ) {
$query->set( 'category_name' , 'turtles');
}
if ( $c == "lizards" ) {
$query->set( 'category_name' , 'lizards');
}
if ( $c == "monkey-tree" ) {
$query->set( 'category_name' , 'monkey-tree');
}
} );