Acf relationship problem

Home Forums Calendar Products Events Calendar PRO Acf relationship problem

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #941040
    Roman
    Participant

    I use the plugin ACF and relationship field for events and posts.

    Querying relationship fields

    To display the current events in the post, I use the, for example, following code:

    	
    <?php
    						/*
    						*  Query posts for a relationship value.
    						*  This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
    						*/
    
    				$events = tribe_get_events(array(
    					  'post_type'=>array(TribeEvents::POSTTYPE),
    				          'posts_per_page' => 12, 
    				          'eventDisplay'=>'upcoming',
    							'meta_query' => array(
    								array(
    									'key' => 'main-events', // name of custom field
    									'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    									'compare' => 'LIKE'
    								)
    							)
    						));
    
    						?>
    
    						<?php if( $events ): ?>
    
    							<div>
    
    							<?php foreach( $events as $event ): ?>
    							<div>		<?php 
    	                                         /*
    						* for image
    						*/
    						echo tribe_event_featured_image( $event->ID, 'cspacing-marker-thumbnail', false );
    								?>
                                                            </div>
    
    								<div>
    
    							<a href="<?php echo get_permalink( $event->ID ); ?>">
    																	
    					<?php echo get_the_title( $event->ID ); ?>
    											</a>
    
    								</div>
    							<?php endforeach; ?>
    							</div>
    						<?php endif; ?>
    

    I want to add in the code above, the output of the date in this format:

    
    	<div class="list-date">
    		<span
    			class="list-dayname"><?php echo apply_filters( 'tribe-mini_helper_tribe_events_ajax_list_dayname', date_i18n( 'D', $postDate ), $postDate, $class ); ?></span>
    		<span
    			class="list-daynumber"><?php echo apply_filters( 'tribe-mini_helper_tribe_events_ajax_list_daynumber', date_i18n( 'd', $postDate ), $postDate, $class ); ?></span>
    	</div>
    

    Please help me how can I use this function in ACF and relationship field:

    
    <?php echo apply_filters( 'tribe-mini_helper_tribe_events_ajax_list_dayname', date_i18n( 'D', $postDate ), $postDate, $class ); ?>
    
    #941206
    Josh
    Participant

    Hey Roman,

    Thanks for reaching out to us!

    I looked over your snippets above and the first one looks great. It looks like the problem with the second is that there are some variables being used that haven’t been defined. If you look where the filters are originally used (<span class=”repo-root js-repo-root”>events-pro</span><span class=”separator”>/</span>views<span class=”separator”>/</span>pro<span class=”separator”>/</span>widgets<span class=”separator”>/</span>modules<span class=”separator”>/</span>single-event.php) you’ll see that the top of the file includes some code and defining of variables that you’ll also need to add within your loop above.

    Let me know if this helps.

    Thanks!

    #941223
    Roman
    Participant

    Thanks for the reply, Josh.

    I found this code:

    
    <?php
    /**
     * Single Event Template for Widgets
     *
     * This template is used to render single events for both the calendar and advanced
     * list widgets, facilitating a common appearance for each as standard.
     *
     * You can override this template in your own theme by creating a file at
     * [your-theme]/tribe-events/widgets/modules/single-widget.php
     *
     * @package TribeEventsCalendarPro
     *
     */
    
    global $post, $wp_query;
    
    $class = "";
    if ( $wp_query->current_post == 1 ) {
    	$class = ' first ';
    }
    if ( $wp_query->current_post + 1 == $wp_query->post_count ) {
    	$class .= ' last ';
    }
    
    $startDate = strtotime( $post->EventStartDate );
    $endDate   = strtotime( $post->EventEndDate );
    $today     = time();
    
    /* If the event starts way in the past or ends way in the future, let's show today's date */
    if ( $today > $startDate && $today < $endDate ) {
    	$postDate = $today;
    } else {
    	$postDate = $startDate;
    }
    
    /* If the user clicked in a particular day, let's show that day as the event date, even if the event spans a few days */
    if ( defined( "DOING_AJAX" ) && DOING_AJAX && isset( $_POST['action'] ) && $_POST['action'] == 'tribe-mini-cal-day' ) {
    	$postDate = strtotime( $_POST["eventDate"] );
    }
    ?>
    

    I tried various options, but to bring a date in this format I have not worked.
    For example, display the date in plain text does not cause problems:

    
    echo tribe_get_start_date( $event->ID );   
    

    If you know how to solve this problem, I will be very grateful to you.

    #941869
    Josh
    Participant

    Hey Roman,

    Thanks for following up with us.

    The variable that you were missing from the second snippet in your first post was the $postDate that was used to get the date information for the event. If you’re looking to incorporate that snippet into the first snippet from your first post, you’ll need to add it within your foreach loop of $events.

    You can then build the $postDate variable using the information from the snippet in your second post. As is, it may not be working since it is pulling information on the global $post rather than the specific event from the loop.

    Try changing the “$post” variable within the snippet from your second post to “$event” for the $startDate, $endDate variables and see if that helps with the other.

    Thanks!

    #983736
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Acf relationship problem’ is closed to new replies.