Home › Forums › ACF PRO › Include meta added via relational post object in an existing query function
The following code had previously successfully included organizers added via my ACF Pro field to the The Events Calendar Pro’s tribe_organizer_upcoming_events loop.
At some point—I’m not exactly sure when—the code ceased to do so. In other words, if an organizer was added to the event meta via the the_organizers ACF field, it is no longer being displayed on the individual’s bio page.
Could anyone take a look at the once-working code, and let me know what may have changed and/or what now needs to be adjusted?
The customized query function, which once worked successfully:
<?php
// Add all events to bio pages
add_action( 'tribe_events_pre_get_posts', function( &$query ) {
if ( $query->tribe_is_event_query && $query->get( 'organizer' ) != '' ) {
// build our own version of the meta query for organizers
$new_meta_query_term = array(
array(
'key' => '_EventOrganizerID',
'value' => $query->get( 'organizer' ),
),
array(
// ACF field
'key' => 'the_organizers',
'compare' => 'LIKE',
'value' => '"' . $query->get( 'organizer' ) . '"'
),
'relation' => 'OR'
);
$meta_query = $query->get( 'meta_query' );
foreach( $meta_query as &$meta_query_term ) {
// replace the meta query term that The Events Calendar made with our new one
if( isset( $meta_query_term['key'] ) && $meta_query_term['key'] == '_EventOrganizerID' ) {
$meta_query_term = $new_meta_query_term;
break;
}
}
$query->set( 'meta_query', $meta_query );
}
} );
The exported PHP for the field group in question:
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5a26fec4071a0',
'title' => 'The Organizers',
'fields' => array(
array(
'key' => 'field_5a26ff1a9337b',
'label' => 'Organizers',
'name' => 'the_organizers',
'type' => 'post_object',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'tribe_organizer',
),
'taxonomy' => array(
),
'allow_null' => 1,
'multiple' => 1,
'return_format' => 'object',
'ui' => 1,
),
array(
'key' => 'field_5b65c8357a7c1',
'label' => 'Master of Ceremony',
'name' => 'ceremony_master',
'type' => 'post_object',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'tribe_organizer',
),
'taxonomy' => array(
),
'allow_null' => 1,
'multiple' => 1,
'return_format' => 'object',
'ui' => 1,
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'tribe_events',
),
),
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'tribe_organizer',
),
),
),
'menu_order' => 0,
'position' => 'side',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
The tribe_organizer_upcoming_events function:
<?php
/**
* Output the upcoming events associated with a venue
*
* @return void
*/
function tribe_organizer_upcoming_events( $post_id = false ) {
$post_id = Tribe__Events__Main::postIdHelper( $post_id );
if ( $post_id ) {
$args = array(
'organizer' => $post_id,
'eventDisplay' => 'list',
'posts_per_page' => apply_filters( 'tribe_events_single_organizer_posts_per_page', 100 ),
'starts_after' => 'now',
);
$html = tribe_include_view_list( $args );
return apply_filters( 'tribe_organizer_upcoming_events', $html );
}
}
The topic ‘Include meta added via relational post object in an existing query function’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.