G’day all … I’m using Pods to build custom post types, and everything is working great … I can access individual pods via Custom Query within a module, but I want to create a JOINed query between two pods, where one pod contains employee information and the other one work schedule.
Doing the join is simple enough, but how do I get it listed as an available Custom Query?
For example, I want a Post Grid that contains those employees that are working today … if I create ( drag-n-drop ) the Posts Grid to my layout and go into Settings, under Post Type ( Custom query ) I can see Employee and I can see Schedule, but I need to add one that is combined.
I found the section in the docs about “Create a filter to customize the display of post data”, but I’m not finding anything for defining a query
Assuming this is possible, pointers to docs and/or examples would be appreciated … the brute force would be to copy / modify the posts-grid module, but that seems a wee bit overkill …
Thanks …
Hi… Same problem I have in past …
To achieve this, you can use the pre_get_posts
action hook to modify the WP_Query arguments before the query runs, which allows you to customize the query to include both pods.
an example of how you could create a custom query for a Post Grid that combines the Employee and Schedule pods. First, you’ll want to create a custom function in your theme’s functions.php
file or a custom plugin:
function my_custom_query_join( $query ) {
// Check if this is the correct query to modify
if ( ! is_admin() && $query->is_main_query() && $query->get( 'post_type' ) === 'custom_query_name' ) {
// Modify the query
$query->set( 'post_type', ['employee', 'schedule'] );
$query->set( 'meta_query', [
'relation' => 'AND',
[
'key' => 'employee_id', // Replace with the appropriate meta key for the employee ID in the schedule pod
'compare' => 'EXISTS',
],
[
'key' => 'schedule_date', // Replace with the appropriate meta key for the schedule date in the schedule pod
'value' => date( 'Y-m-d' ),
'compare' => '=',
'type' => 'DATE',
],
] );
}
}
add_action( 'pre_get_posts', 'my_custom_query_join' );
you’ll need to add the custom query option in Beaver Builder. You can do this by creating a new Custom Query in the Post Grid module settings:
- Drag-n-drop the Posts Grid module to your layout.
- Go to Settings > Content > Source > Post Type, and choose “Custom query.”
- In the Custom Query field, enter the custom query name you used in the
functions.php
code (e.g., ‘custom_query_name’).
Now the Post Grid will display the combined Employee and Schedule pods based on the custom query you defined. You can adjust the code in the functions.php
file to further customize the query to fit your specific requirements.