Support

Account

Home Forums Front-end Issues Include meta added via relational post object in an existing query function

Solving

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 );
    		}
    	}
  • Since you are interacting directly with the query class of the other plugin you best chance at a solution would be to ask support for that plugin. I can’t really tell by looking at your code because I don’t know how the other plugin works, but given what I know there isn’t any change is ACF that would have caused it to stop working.

  • Thanks John,

    I understand, and sincerely appreciate you taking the time to respond at all nonetheless.

    Unfortunately, the Tribe support staff has consistently proven quite eager to avoid providing any assistance said to fall beyond their “Scope of Support.” This was the gist of their response —

    I did look at your PHP file and it looks very similar (other than ACF logic) to what The Events Calendar is already doing: https://github.com/moderntribe/the-events-calendar/blob/4.9.1.1/src/Tribe/Query.php#L455-L461

    I’m not personally very familiar with ACF, but I know their codebase has received significant updates in recent history so maybe their logic isn’t as it used to be.

    If any easier, would it be possible to help me write a standalone query, for placement within the Tribe single-organizer.php template (both attached and pasted below), instead? Like the native tribe_organizer_upcoming_events function, the idea——in theory——would be for it to find any Tribe single event post where the organizer ID was added to the event meta, and return each given event ID.

    In other words, it would look for any Tribe event where the given organizer ID is selected via the ACF Pro field “the_organizers”.

    I’ve also attached a detailed screenshot for additional reference, as well as a few potentially relevant example links:

    Single Event Page

    Speaker | Organizer Page
    (set by native Tribe field–upcoming event display)

    Speaker | Organizer Page
    (set by ACF relational object field–upcoming event not display)

    <?php
    /**
     * Single Organizer Template
     * The template for an organizer. By default it displays organizer information and lists
     * events that occur with the specified organizer.
     *
     * This view contains the filters required to create an effective single organizer view.
     *
     * You can recreate an ENTIRELY new single organizer view by doing a template override, and placing
     * a Single_Organizer.php file in a tribe-events/pro/ directory within your theme directory, which
     * will override the /views/pro/single_organizer.php.
     *
     * You can use any or all filters included in this file or create your own filters in
     * your functions.php. In order to modify or extend a single filter, please see our
     * readme on templates hooks and filters (TO-DO)
     *
     * @package TribeEventsCalendarPro
     *
     * @version 4.4.28
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    $organizer_id = get_the_ID();
    ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    	<div class="tribe-events-organizer">
    			<p class="tribe-events-back">
    				<a href="<?php echo esc_url( tribe_get_events_link() ); ?>" rel="bookmark"><?php printf( __( '&larr; Back to %s', 'tribe-events-calendar-pro' ), tribe_get_event_label_plural() ); ?></a>
    			</p>
    
    		<?php do_action( 'tribe_events_single_organizer_before_organizer' ) ?>
    		<div class="tribe-events-organizer-meta tribe-clearfix">
    
    				<!-- Organizer Title -->
    				<?php do_action( 'tribe_events_single_organizer_before_title' ) ?>
    				<h1 class="tribe-organizer-name"><?php echo tribe_get_organizer( $organizer_id ); ?></h1>
    				<?php do_action( 'tribe_events_single_organizer_after_title' ) ?>
    
    				<!-- Organizer Meta -->
    				<?php do_action( 'tribe_events_single_organizer_before_the_meta' ); ?>
    				<?php echo tribe_get_organizer_details(); ?>
    				<?php do_action( 'tribe_events_single_organizer_after_the_meta' ) ?>
    
    				<!-- Organizer Featured Image -->
    				<?php echo tribe_event_featured_image( null, 'full' ) ?>
    
    				<!-- Organizer Content -->
    				<?php if ( get_the_content() ) { ?>
    				<div class="tribe-organizer-description tribe-events-content">
    					<?php the_content(); ?>
    				</div>
    				<?php } ?>
    
    			</div>
    			<!-- .tribe-events-organizer-meta -->
    		<?php do_action( 'tribe_events_single_organizer_after_organizer' ) ?>
    
    		<!-- Upcoming event list -->
    		<?php do_action( 'tribe_events_single_organizer_before_upcoming_events' ) ?>
    
    		<?php
    		// Use the tribe_events_single_organizer_posts_per_page to filter the number of events to get here.
    		echo tribe_organizer_upcoming_events( $organizer_id ); ?>
    
    		<?php do_action( 'tribe_events_single_organizer_after_upcoming_events' ) ?>
    
    	</div><!-- .tribe-events-organizer -->
    	<?php
    	do_action( 'tribe_events_single_organizer_after_template' );
    endwhile;
  • Thanks John,

    I understand, and sincerely appreciate you taking the time to respond at all nonetheless.

    Unfortunately, the Tribe support staff has consistently proven quite eager to avoid providing any assistance said to fall beyond their “Scope of Support.” This was the gist of their response —

    I did look at your PHP file and it looks very similar (other than ACF logic) to what The Events Calendar is already doing: https://github.com/moderntribe/the-events-calendar/blob/4.9.1.1/src/Tribe/Query.php#L455-L461

    I’m not personally very familiar with ACF, but I know their codebase has received significant updates in recent history so maybe their logic isn’t as it used to be.

    If any easier, would it be possible to help me write a standalone query, for placement within the Tribe single-organizer.php template (both attached and pasted below), instead? Like the native tribe_organizer_upcoming_events function, the idea——in theory——would be for it to find any Tribe single event post where the organizer ID was added to the event meta, and return each given event ID.

    In other words, it would look for any Tribe event where the given organizer ID is selected via the ACF Pro field “the_organizers”.

    I’ve also attached a detailed screenshot for additional reference, as well as a few potentially relevant example links:

    Single Event Page

    Speaker | Organizer Page
    (set by native Tribe field–upcoming event display)

    Speaker | Organizer Page
    (set by ACF relational object field–upcoming event not display)

    <?php
    /**
     * Single Organizer Template
     * The template for an organizer. By default it displays organizer information and lists
     * events that occur with the specified organizer.
     *
     * This view contains the filters required to create an effective single organizer view.
     *
     * You can recreate an ENTIRELY new single organizer view by doing a template override, and placing
     * a Single_Organizer.php file in a tribe-events/pro/ directory within your theme directory, which
     * will override the /views/pro/single_organizer.php.
     *
     * You can use any or all filters included in this file or create your own filters in
     * your functions.php. In order to modify or extend a single filter, please see our
     * readme on templates hooks and filters (TO-DO)
     *
     * @package TribeEventsCalendarPro
     *
     * @version 4.4.28
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    $organizer_id = get_the_ID();
    ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    	<div class="tribe-events-organizer">
    			<p class="tribe-events-back">
    				<a href="<?php echo esc_url( tribe_get_events_link() ); ?>" rel="bookmark"><?php printf( __( '&larr; Back to %s', 'tribe-events-calendar-pro' ), tribe_get_event_label_plural() ); ?></a>
    			</p>
    
    		<?php do_action( 'tribe_events_single_organizer_before_organizer' ) ?>
    		<div class="tribe-events-organizer-meta tribe-clearfix">
    
    				<!-- Organizer Title -->
    				<?php do_action( 'tribe_events_single_organizer_before_title' ) ?>
    				<h1 class="tribe-organizer-name"><?php echo tribe_get_organizer( $organizer_id ); ?></h1>
    				<?php do_action( 'tribe_events_single_organizer_after_title' ) ?>
    
    				<!-- Organizer Meta -->
    				<?php do_action( 'tribe_events_single_organizer_before_the_meta' ); ?>
    				<?php echo tribe_get_organizer_details(); ?>
    				<?php do_action( 'tribe_events_single_organizer_after_the_meta' ) ?>
    
    				<!-- Organizer Featured Image -->
    				<?php echo tribe_event_featured_image( null, 'full' ) ?>
    
    				<!-- Organizer Content -->
    				<?php if ( get_the_content() ) { ?>
    				<div class="tribe-organizer-description tribe-events-content">
    					<?php the_content(); ?>
    				</div>
    				<?php } ?>
    
    			</div>
    			<!-- .tribe-events-organizer-meta -->
    		<?php do_action( 'tribe_events_single_organizer_after_organizer' ) ?>
    
    		<!-- Upcoming event list -->
    		<?php do_action( 'tribe_events_single_organizer_before_upcoming_events' ) ?>
    
    		<?php
    		// Use the tribe_events_single_organizer_posts_per_page to filter the number of events to get here.
    		echo tribe_organizer_upcoming_events( $organizer_id ); ?>
    
    		<?php do_action( 'tribe_events_single_organizer_after_upcoming_events' ) ?>
    
    	</div><!-- .tribe-events-organizer -->
    	<?php
    	do_action( 'tribe_events_single_organizer_after_template' );
    endwhile;
  • Thanks John,

    I understand, and sincerely appreciate you taking the time to respond at all nonetheless.

    Unfortunately, the Tribe support staff has consistently proven quite eager to avoid providing any assistance said to fall beyond their “Scope of Support.” This was the gist of their response —

    I did look at your PHP file and it looks very similar (other than ACF logic) to what The Events Calendar is already doing: https://github.com/moderntribe/the-events-calendar/blob/4.9.1.1/src/Tribe/Query.php#L455-L461

    I’m not personally very familiar with ACF, but I know their codebase has received significant updates in recent history so maybe their logic isn’t as it used to be.

    If any easier, would it be possible to help me write a standalone query, for placement within the Tribe single-organizer.php template (pasted below), instead? Like the native tribe_organizer_upcoming_events function, the idea——in theory——would be for it to find any Tribe single event post where the organizer ID was added to the event meta, and return each given event ID.

    In other words, it would look for any Tribe event where the given organizer ID is selected via the ACF Pro field “the_organizers”.

    I’ve also included a link to a screenshot for additional reference, plus a few potentially relevant example links, below:

    Screenshot

    Single Event Page

    Speaker | Organizer Page
    (set by native Tribe field–upcoming event display)

    Speaker | Organizer Page
    (set by ACF relational object field–upcoming event not display)

    <?php
    /**
     * Single Organizer Template
     * The template for an organizer. By default it displays organizer information and lists
     * events that occur with the specified organizer.
     *
     * This view contains the filters required to create an effective single organizer view.
     *
     * You can recreate an ENTIRELY new single organizer view by doing a template override, and placing
     * a Single_Organizer.php file in a tribe-events/pro/ directory within your theme directory, which
     * will override the /views/pro/single_organizer.php.
     *
     * You can use any or all filters included in this file or create your own filters in
     * your functions.php. In order to modify or extend a single filter, please see our
     * readme on templates hooks and filters (TO-DO)
     *
     * @package TribeEventsCalendarPro
     *
     * @version 4.4.28
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    $organizer_id = get_the_ID();
    ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    	<div class="tribe-events-organizer">
    			<p class="tribe-events-back">
    				<a href="<?php echo esc_url( tribe_get_events_link() ); ?>" rel="bookmark"><?php printf( __( '&larr; Back to %s', 'tribe-events-calendar-pro' ), tribe_get_event_label_plural() ); ?></a>
    			</p>
    
    		<?php do_action( 'tribe_events_single_organizer_before_organizer' ) ?>
    		<div class="tribe-events-organizer-meta tribe-clearfix">
    
    				<!-- Organizer Title -->
    				<?php do_action( 'tribe_events_single_organizer_before_title' ) ?>
    				<h1 class="tribe-organizer-name"><?php echo tribe_get_organizer( $organizer_id ); ?></h1>
    				<?php do_action( 'tribe_events_single_organizer_after_title' ) ?>
    
    				<!-- Organizer Meta -->
    				<?php do_action( 'tribe_events_single_organizer_before_the_meta' ); ?>
    				<?php echo tribe_get_organizer_details(); ?>
    				<?php do_action( 'tribe_events_single_organizer_after_the_meta' ) ?>
    
    				<!-- Organizer Featured Image -->
    				<?php echo tribe_event_featured_image( null, 'full' ) ?>
    
    				<!-- Organizer Content -->
    				<?php if ( get_the_content() ) { ?>
    				<div class="tribe-organizer-description tribe-events-content">
    					<?php the_content(); ?>
    				</div>
    				<?php } ?>
    
    			</div>
    			<!-- .tribe-events-organizer-meta -->
    		<?php do_action( 'tribe_events_single_organizer_after_organizer' ) ?>
    
    		<!-- Upcoming event list -->
    		<?php do_action( 'tribe_events_single_organizer_before_upcoming_events' ) ?>
    
    		<?php
    		// Use the tribe_events_single_organizer_posts_per_page to filter the number of events to get here.
    		echo tribe_organizer_upcoming_events( $organizer_id ); ?>
    
    		<?php do_action( 'tribe_events_single_organizer_after_upcoming_events' ) ?>
    
    	</div><!-- .tribe-events-organizer -->
    	<?php
    	do_action( 'tribe_events_single_organizer_after_template' );
    endwhile;
  • Rather than do that let’s see if we can work out the issue.

    I am assuming that the line in their function

    
    return apply_filters( 'tribe_organizer_upcoming_events', $html );
    

    eventually causes your filter to be run.

    The first thing we need to find out is if your filter is running at all. Do you know that this is the case? If not then

    
    <?php
    
    // Add all events to bio pages
    add_action( 'tribe_events_pre_get_posts', function( &$query ) {
        
        // see if this filter is being called
        echo 'my filter was called'; die;
        
        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 );
        }
    } );
    
  • I can’t even begin to explain how much I appreciate your help, John. You, personally, are seen everywhere across this forum, going above and beyond to provide support to an extent that I don’t see from any support team at all (and doing so for arguably as valuable a plugin as exists). In all sincerity, thank you. It’s nothing short of amazing.

    Anyways, using the code you’ve provided above, I can confirm that, yes, the filter is in indeed being called.

  • Thank you, I do this for a couple of reasons, one of them being that I feel ACF is the most valuable WP plugin that exists and will become more so with the bad direction I feel that WP is going with their block editor.

    Anyway. Remove the line of code I added before and replace it with this

    
    if ($query->get('organizer')) {
      var_dump($query->get('organizer')); echo '<br />';
    }
    echo '<pre>'; print_r($query); die;
    

    and post whatever it is that outputs. There’s going to be a long nested query, but I need to know what’s in it.

  • This reply has been marked as private.
  • Did you include this part, I’d like to see what’s in $query->get('organizer')

    
    if ($query->get('organizer')) {
      var_dump($query->get('organizer')); echo '<br />';
    }
    
  • This reply has been marked as private.
  • This reply has been marked as private.
  • The value of the query variable is not being output, make sure that is before the die statement and not after…. unless I’m missing it. No need to post the query array again, just the value of that variable is all I need.

  • This reply has been marked as private.
  • You have a couple of problems here

    First is that $query->get( 'organizer' ) is returning nothing because it is not set. It appears that this has been changed to tribe_organizer. You’d thing they would tell you this after looking at your code. So, I don’t think that your condition is ever being met. Try this to find out

    
    if ( $query->tribe_is_event_query && $query->get( 'organizer' ) != '' ) {
      echo 'query var set'; die;
    

    I think that the second issue is that this value contains a holding a name and you are querying a post object field that contains a post ID.

    You need the post ID for this organizer and not the name.

    Not sure how to solve this.

    Tell me more about this query we’re trying to modify, it is a sub query? The information for the organizer has already been shown and now you are trying to show the events that they are organizing?

  • Hi John — I hope you had a nice, relaxing and well-deserved weekend.

    $query->get( ‘organizer’ ) is returning nothing because it is not set. It appears that this has been changed to tribe_organizer.

    You appear to be correct. With the code above in place, the die function is never returned. Once changed to get( 'tribe_organizer' ), “query var set” is returned.

    So I gave this a look:

    if ($query->get('tribe_organizer')) {
      var_dump($query->get('tribe_organizer')); echo '<br />';
    }

    Which returned:
    string(14) "alex-greenbaum"

    So —

    You need the post ID for this organizer and not the name.

    Given what you’ve explained to be what we’re looking for, would either of these solutions, if nothing else, be helpful starting points?

    Solution 1 (based on this native Tribe function tribe_get_organizer_ids)

    // search the ID of organizer
    $organizers = tribe_get_organizer_ids($id);
    
    // retrieve name of organizer
    // will create an events loop tribe_get_events
    $orgName = array();
    foreach($organizers as $organizerId) {
      $orgName[] = tribe_get_organizer($organizerId);
    }

    And, another here: Solution 2

    Additionally, all of the native Tribe organizer-related functions, straight from their documentation here.

    Tell me more about this query we’re trying to modify, it is a sub query? The information for the organizer has already been shown and now you are trying to show the events that they are organizing?

    That is correct. I am trying to display all of the events for which the organizer has been set as an organizer/speaker.

    The “Organizer” page, as it is natively called, is said to be a custom taxonomy.

    Bear with me here, because it may (almost certainly will) get a little confusing. I have changed the label of this post-type (or custom taxonomy?) to “Speakers | Organizers”. With some template customization, and the help of ACF Pro, from the single event edit screen, I use the native meta section to select what is being output under a “Speakers” header in the meta section on the front end, and a separate ACF Pro relational object field to select what is being output under an “Organizers” header in the meta section on the front end. Both the native meta object selection field and the ACF Pro selection field are pulling from the same pool of “Speakers | Organizers.”

    That’s all working as intended.

    By default, the individual Speaker | Organizers pages then display all upcoming events that the Speaker | Organizer is tied to. For a while, that solution I posted in the first post of this thread, ensured that the upcoming event was posted on the individual’s Speaker | Organizer, regardless of whether they were attached via the native tribe meta field or the ACF Pro relational field. Now, however, the upcoming events loop found on the individual Speaker | Organizer page is only pulling in that respective Speaker | Organizer’s upcoming event if it were set via the native meta field (while failing to recognize it as an upcoming event if set via the ACF Pro relational field).

  • So It really depends on if there is more that one organizer, this is really just a guess, but it adds all the organizer IDs to the query if there is more than one.

    
    
      
      $meta_query = array(
        'relation' => 'OR',
        array(
          // I don't know if this needs to be changed
          'key'   => '_EventOrganizerID',
          'value' => $query->get('tribe_organizer'),
        )
      );
      $organizers = tribe_get_organizer_ids($id);
      foreach ($organizers as $organizer) {
        // add each organizer
        $meta_query[] = array(
          'key' => 'the_organizers',
          'compare' => 'LIKE',
          'value' => '"'.$organizer.'"'
        );
      }
    
  • Thanks John.

    It’s entirely possible that I’m implementing your recently suggested code in a manner other than what you had in mind, but either way, still no luck. For what it’s worth, my attempted variations have included both 'value' => $query->get('tribe_organizer') and 'value' => $query->get('organizer').

    At this point, personal guilt with respect to your time is starting to creep in. If this has become too complicated, and/or if these efforts have come to require too much hand-holding, I completely understand. Just let me know.

    Regardless of the ultimate outcome, I can’t thank you enough for the time you’ve already dedicated to assisting me.

  • Sorry I have not been replying, it has gotten a little busy this week.

    The main issue is that I’m not familiar enough with the events plugin, I just don’t use it as I generally build custom events sections on the site. The events plugin is usually 1 of 2 things. Either it is overkill for what my clients need or some feature is not done the way my clients want it done.

    Anyway, looking back over the query outputs you supplied it also appears that there is not organizer meta query being done by the plugin at all. What this means is that the meta query that you’re trying to replace is not there, does not get replaced and so your changes are not applied. It appears that there have been quite a few changes in that plugin since this code was first put in place.

    Potentially this could be a priority issue and your filter is being run before the other plugin is applying the meta query

    You could try increasing the priority of your function to see if you can get a query output that actually shows the meta query being done.

    
    add_action('tribe_events_pre_get_posts', function($query) {
      echo '<pre>'; print_r($query); die;
    }, 20);
    
  • If there’s one thing I do know, it’s that the last thing you owe me is an apology. Thanks for following up.

    Unfortunately, increasing the priority made no difference.

    Ignoring the apparent changes to the Tribe events plugin for a moment, your last comment on the meta query got me thinking about this WP Sweep plugin I installed and used not too long ago —

    I can’t be certain with respect to the timing, as it never occurred to me to check whether or not an issue in this area manifested, but it feels like it may have been close.

    Is it possible that in “sweeping” the database, I inadvertently purged some metadata that had once been holding the query together? At this point, I have to assume we’re too far removed (and too uncertain on the timing) to make restoring the database a viable option. But, with respect to ACF Pro and your intimate understanding of its inner-workings, is there anything I might be able to do to repair the damage done (or re-establish the data that may have been lost)?

    For what it’s worth, I just finished performing WordPress’ native database repair function on my dev environment, but it didn’t find any issues.

    That aside, a couple of options that I’m considering and wondering whether or not you think it’s time to give them a shot (happy to continue down our current path if that’s your preference/suggestion):

    1. Is there anything specific you’d recommend I ask the Tribe support team? They certainly won’t put forth any meaningful effort toward resolving the overall issue, but hopefully they can provide more specific answers on relevant functionality that I can’t. Is there anything in particular that might be especially illuminating with respect to troubleshooting this?
    2. Should I look into another means of separating speakers and organizers on the front-end of the single event pages, via different ACF field-type?

      For example, maybe something that would allow me to set all “Speakers | Organizers” via the native Tribe meta field selection, then use an ACF field to effectively mark or define which “Speaker | Organizer” should be listed under the “Speaker” header in the front-end meta section. Not sure how feasible this would be before digging in to the myriad of ACF field options.

    3. Should we consider the standalone query option I mentioned previously? That reference pasted below:

      If any easier, would it be possible to help me write a standalone query, for placement within the Tribe single-organizer.php template (pasted below), instead? Like the native tribe_organizer_upcoming_events function, the idea——in theory——would be for it to find any Tribe single event post where the organizer ID was added to the event meta, and return each given event ID.

      In other words, it would look for any Tribe event where the given organizer ID is selected via the ACF Pro field “the_organizers”.

  • On some level, I’m certainly wishing that I went the custom events section route as you tend to do. That said, for all of my programming knowledge deficiencies, I find these troubleshooting efforts incredibly addictive, and they’re the reason I’m shoulder deep in javascript training courses and the like. I truly can’t get enough of it. Anyways —

    Shot in the dark, but maybe the following could help us (in some small way) get to the bottom of this, or blaze the best alternative solution path:

    As I have hopefully made clear, “Organizers” is a native custom post type included with the Tribe plugin. So for the sake of testing and my own understanding, I moved from my functions.php over to the single organizer page template (organizer.php).

    We’ve established (or so I meant to) that the upcoming events related to the given organizer are output with echo tribe_organizer_upcoming_events( $organizer_id );

    So I added the following to the template file:

    <?php
    // tribe_get_organizers_ids() function with the event ID I've been testing on
    $test_organizer_ids = tribe_get_organizer_ids(38901);

    And this below the native echo tribe_organizer_upcoming_events( $organizer_id );:

    <?php
    		echo '<pre>';
    print_r($test_organizer_ids);
    echo '</pre>';

    Which returned the organizer IDs, but—predictably, I’m sure—only the IDs of the Organizers set via the native tribe meta field:

    Array
    (
        [0] => 16671
        [1] => 29406
        [2] => 29415
        [3] => 30056
    )

    There’s a good chance this does nothing to help you/us, but at least I can feel slightly less guilt in knowing that you know that I’m not just sitting on my hands while you provide above-and-beyond support.

    Here’s the full edited template file. Maybe the action filters provide some clue with respect to timing as well?

    <?php
    /**
     * Single Organizer Template
     * The template for an organizer. By default it displays organizer information and lists
     * events that occur with the specified organizer.
     *
     * This view contains the filters required to create an effective single organizer view.
     *
     * You can recreate an ENTIRELY new single organizer view by doing a template override, and placing
     * a Single_Organizer.php file in a tribe-events/pro/ directory within your theme directory, which
     * will override the /views/pro/single_organizer.php.
     *
     * You can use any or all filters included in this file or create your own filters in
     * your functions.php. In order to modify or extend a single filter, please see our
     * readme on templates hooks and filters (TO-DO)
     *
     * @package TribeEventsCalendarPro
     *
     * @version 4.4.28
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    $organizer_id = get_the_ID();
    $test_organizer_ids = tribe_get_organizer_ids(38901);
    
    ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    	<div class="tribe-events-organizer">
    			<p class="tribe-events-back">
    				<a href="<?php echo esc_url( tribe_get_events_link() ); ?>" rel="bookmark"><?php printf( __( '&larr; Back to %s', 'tribe-events-calendar-pro' ), tribe_get_event_label_plural() ); ?></a>
    			</p>
    
    		<?php do_action( 'tribe_events_single_organizer_before_organizer' ) ?>
    		<div class="tribe-events-organizer-meta tribe-clearfix">
    
    				<!-- Organizer Title -->
    				<?php do_action( 'tribe_events_single_organizer_before_title' ) ?>
    				<h1 class="tribe-organizer-name"><?php echo tribe_get_organizer( $organizer_id ); ?></h1>
    				<?php do_action( 'tribe_events_single_organizer_after_title' ) ?>
    
    				<!-- Organizer Meta -->
    				<?php do_action( 'tribe_events_single_organizer_before_the_meta' ); ?>
    				<?php echo tribe_get_organizer_details(); ?>
    				<?php do_action( 'tribe_events_single_organizer_after_the_meta' ) ?>
    
    				<!-- Organizer Featured Image -->
    				<?php echo tribe_event_featured_image( null, 'full' ) ?>
    
    				<!-- Organizer Content -->
    				<?php if ( get_the_content() ) { ?>
    				<div class="tribe-organizer-description tribe-events-content">
    					<?php the_content(); ?>
    				</div>
    				<?php } ?>
    
    			</div>
    			<!-- .tribe-events-organizer-meta -->
    		<?php do_action( 'tribe_events_single_organizer_after_organizer' ) ?>
    
    		<!-- Upcoming event list -->
    		<?php do_action( 'tribe_events_single_organizer_before_upcoming_events' ) ?>
    
    		<?php
    		// Use the tribe_events_single_organizer_posts_per_page to filter the number of events to get here.
    		echo tribe_organizer_upcoming_events( $organizer_id );
    		echo '<pre>';
    print_r($test_organizer_ids);
    echo '</pre>';
    		 ?>
    
    		<?php do_action( 'tribe_events_single_organizer_after_upcoming_events' ) ?>
    
    	</div><!-- .tribe-events-organizer -->
    	<?php
    	do_action( 'tribe_events_single_organizer_after_template' );
    endwhile;
  • I’m assuming that this is the part you are trying to alter, where this part of the code is

    
    echo tribe_organizer_upcoming_events( $organizer_id );
    

    I tried looking the the code for the free version of the plugin, but it does not include this function.

    There are 2 possibilities that I would look at. The first is to look at this function and how it works and see what I’d need to do to. But in order to figure that out I’d need to see all of the plugins code so I could follow everything through to figure out what it’s doing.

    The second would be to replace that line of code with a call to my own function where I would run my own query. Then I would try to use the plugin’s provided template for showing each upcoming event or if that’s not possible I’d construct my own template part for showing them. This is actually what is suggested here https://theeventscalendar.com/support/forums/topic/changing-the-upcoming-events-view-for-single-organizer-php/, but they are not very forthcoming with a real solution. Event doing this would require access to the code.

    Looking at the information you have you’d need to figure out what to use to get “upcoming events” Is this a custom field or is this the standard WP date for the post?

  • Sure, so here’s 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 );
    		}
    	}

    Here (more importantly, I hope) is the support page for using tribe_get_events(), which they go on to describe as “a neat little helper function that makes it easy to retrieve event data when building customizations,” before offering something of a basic-use tutorial, as well as how it relates to the WP_Query class or the get_posts() function:
    https://support.theeventscalendar.com/666307-Using-tribe_get_events

    Not sure whether this could prove helpful in any way, but here is the support page for Tribe Settings API:
    https://support.theeventscalendar.com/489740-Tribe-Settings-API

    An overview of the tribe_get_organizer function parameters:
    https://theeventscalendar.com/function/tribe_get_organizer/

    I’d be happy to additionally provide you with any of the “Pro” plugin files you’d think might be helpful. I’m not sure how appropriate it would be to do so here, but let me know if that’s something worth exploring.

    Finally, this may be so dated that it’s ultimately worthless at this point in time, but here were all of the Events Calendar Custom fields, as provided about three years ago:

    The Events Calendar Custom Fields @3.9
    
    Event Custom Post Type ( tribe_events )
    _EventAllDay
    _EventStartDate
    _EventEndDate
    _EventDuration
    _EventVenueID
    _EventShowMapLink
    _EventShowMap
    _EventCurrencySymbol
    _EventCurrencyPosition
    _EventCost
    _EventCostMin
    _EventCostMax
    _EventURL
    _EventOrganizerID
    _EventPhone
    _EventHideFromUpcoming			
    _FacebookID
    _EventOrigin
    
    Venue Custom Post Type ( tribe_venue )
    _VenueVenue
    _VenueCountry
    _VenueAddress
    _VenueCity
    _VenueStateProvince
    _VenueState
    _VenueProvince
    _VenueZip
    _VenuePhone
    _VenueURL
    
    To get Venue ID for an event use this function:
    
    tribe_get_venue_id( $event_id );
    			
    Organizer Custom Post Type ( tribe_organizer )
    _OrganizerOrganizer
    _OrganizerEmail
    _OrganizerWebsite
    _OrganizerPhone
    
    To get Organizer ID for an event use this function:
    
    tribe_get_organizer_id( $event_id );
    
    Capabilities
    edit_tribe_event
    read_tribe_event
    delete_tribe_event
    delete_tribe_events
    edit_tribe_events
    edit_others_tribe_events
    delete_others_tribe_events
    publish_tribe_events
    edit_published_tribe_events
    delete_published_tribe_events
    delete_private_tribe_events
    edit_private_tribe_events
    read_private_tribe_events
    
    edit_tribe_venue
    read_tribe_venue
    delete_tribe_venue
    delete_tribe_venues
    edit_tribe_venues
    edit_others_tribe_venues
    delete_others_tribe_venues
    publish_tribe_venues
    edit_published_tribe_venues
    delete_published_tribe_venues
    delete_private_tribe_venues
    edit_private_tribe_venues
    read_private_tribe_venues
    
    edit_tribe_organizer
    read_tribe_organizer
    delete_tribe_organizer
    delete_tribe_organizers
    edit_tribe_organizers
    edit_others_tribe_organizers
    delete_others_tribe_organizers
    publish_tribe_organizers
    edit_published_tribe_organizers
    delete_published_tribe_organizers
    delete_private_tribe_organizers
    edit_private_tribe_organizers
    read_private_tribe_organizers
  • This is where it really starts going down a rabbit hole. The function tribe_organizer_upcoming_events() doesn’t really do anything. What I would really need is the function that actually constructs and runs the WP_Query. This function calls tribe_include_view_list() and more than likely that function calls other functions and filters before the query is constructed an run somewhere.

    And I really wouldn’t be able to construct a custom query based on the other information I have. Plus, we really don’t care about the organizer because you want to swap out anything it’s doing there with the value of an acf relationship field.

    If I had access to 100% of the code for this plugin so that I can follow what’s going on where and keep things organized and several hours I’m sure I could find a solution. But trying to do this here it’s confusing, and I don’t even know what to ask you for or tell you what to look for.

    So I’m going to circle back to something we looked at before. Looking at the query that’s being done where you want to make the change. Looking back at the WP_Qeury objects that you posted, none of them look like the query that you actually want to modify because none of them include any query parameter that would filter the posts by an organizer. So what you need to do is to see all of the queries being done and then figure out what one needs to be altered.

    How to you do this.

    
    add_action('tribe_events_pre_get_posts', 'log_queries');
    function log_queries($query) {
      ob_start();
      print_r($query);
      error_log(ob_get_clean());
    }
    

    What will this do? This will write every query done on a page load to your php error log. You load the page were you want to modify the query. then you download the error log and crawl though it until you locate the query object that is actually querying events for a specific organizer. If you can figure that out then you’ll have a better idea what you need to do to detect which query to alter and what you need to do to alter it.

  • This reply has been marked as private.
Viewing 25 posts - 1 through 25 (of 28 total)

You must be logged in to reply to this topic.

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.