Query for getting pages within same category
-
I have added a custom category to my pages: ‘sidekategori’
I will be using this to group pages together and to show related pages.
I’m using Elementor for layout and I’ve hit a wall trying to make a query that only includes pages with the same taxonomy ‘sidekategori’ as the current one.
To use it as a filter in Elementor I have to create it as an action – so far so good. I’ve two other filters running that shows siblings and direct siblings, they’re working fine.
But I can’t figure out how to filter by this custom category.
This is my code:
// Getting same sidekategori of current page add_action( 'elementor/query/pages_same_cpt_cat_filter', function( $query ) { //get ID of current page $id = get_queried_object_id(); // get current taxonomy $tax = get_the_terms( $id, 'sidekategori'); $query->set( 'taxonomy', 'sidekategori'); $query->set( 'field', 'slug'); $query->set( 'slug', $tax[0]->slug ); } );
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Query for getting pages within same category’ is closed to new replies.