I’m working on a WordPress site where I use ACF to create relationships between “training programs” and “jobs”. Here’s the setup:
- I have a custom field group named “Training Program”.
- In this group, there’s a relational field called “job” that links to a custom post type named “job”.
My goal is to create a custom query in Elementor to display only the jobs associated with a specific training program. Here’s the code I used for the query:
function jobs_query( $query ) {
$jobs_id = get_field('job', get_the_ID());
$query->set( 'post_type', 'job' );
$query->set( 'post__in', $jobs_id );
}
add_action( 'elementor/query/13600', 'jobs_query' );
Problem:
When I use this code, the entire page becomes blank. No specific error is displayed, but it seems that the custom query is causing the issue.
To debug, I added another hook in the footer to check if get_field
retrieves the expected data:
add_action( 'wp_footer', function() {
if ( is_singular( 'training_program' ) ) {
$training_program_id = get_the_ID();
$jobs = get_field( 'job', $training_program_id );
echo '<pre>';
print_r( $jobs );
echo '</pre>';
}
});
With this code, the related jobs are displayed correctly. The ACF field seems well-configured, and the relationships are in place.
Question: Why does the Elementor custom query fail while the get_field function retrieves the data correctly? How can I resolve this issue to display the related jobs in an Elementor loop?
Thank you in advance for your help!