Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ellegaarddk
Last active October 10, 2023 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ellegaarddk/21a7097b3e5fb5f0fc368da388774e45 to your computer and use it in GitHub Desktop.
Save ellegaarddk/21a7097b3e5fb5f0fc368da388774e45 to your computer and use it in GitHub Desktop.
Custom queries for Elementor use - WordPress. To be inserted in you theme's functions.php or a custom made functions plugin.
<php
/*
* Custom queries for Elementor
* by ellegaard ID
*/
/* Get direct children of current page
*
* for query ID use 'pages_direct_child_filter'
*/
add_action( 'elementor/query/pages_direct_child_filter', function( $query ) {
// Get current page
$current_page = get_queried_object_id();
// Modify the query
$query->set( 'post_parent', $current_page );
} );
/*
* Get siblings of current page
*
* for query ID use 'pages_siblings_filter'
*/
add_action( 'elementor/query/pages_siblings_filter', function( $query ) {
//get parent ID
$id = wp_get_post_parent_id( get_the_ID() );
//modify query
$query->set( 'post_parent', $id );
} );
/*
* Getting same costum taxonomy of current page
*
* for query ID use 'pages_same_cpt_cat_filter'
*/
add_action( 'elementor/query/pages_same_cpt_cat_filter', function( $query ) {
// get ID of current page
$id = get_queried_object_id();
// tax terms of chosen taxonomy - insert instead of 'custom_taxonomy_name'
$tax = get_the_terms( $id, 'custom_taxonomy_name');
// choose slug as field
$query->set( 'field', 'slug');
// get slug of current tax
$query->set( 'tax_query', $tax[0]->slug );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment