-
-
Save asadowski10/369b1b60e9280e9b386043d82623f5e0 to your computer and use it in GitHub Desktop.
<?php | |
add_filter( 'acf/fields/relationship/query/key=field_59006ee8b9a7b', 'bea_acf_relationship', 10, 3 ); | |
add_filter( 'acf/load_value/name=featured_event', 'bea_acf_relationship', 10, 3 ); | |
/** | |
* | |
* Display all events in Relationship field ( future, past ) | |
* | |
* @param $args | |
* @param $field | |
* @param $object_id | |
* | |
* @return mixed | |
* @author Alexandre Sadowski | |
*/ | |
function bea_acf_relationship( $args, $field, $object_id ) { | |
if ( ! class_exists( 'Tribe__Events__Query' ) ) { | |
return $args; | |
} | |
remove_action( 'pre_get_posts', array( 'Tribe__Events__Query', 'pre_get_posts' ), 50 ); | |
return $args; | |
} |
Hi, this is exactly what i was searching for, but where to put this code ? Theme's functions.php, plugin's acf.php ? Thanks ;-)
Hi, this is exactly what i was searching for, but where to put this code ? Theme's functions.php, plugin's acf.php ? Thanks ;-)
Yes, in functions.php works.
This is working great, but do you know that the selected past event disappears from the edit screen right after you save the post so that if you ever want to update the post, you have to select the past event again? https://wordpress.org/support/topic/acf-relationship-field-past-events-only-sort-of-work/ I was wondering if you knew a workaround for that.
This is working great, but do you know that the selected past event disappears from the edit screen right after you save the post so that if you ever want to update the post, you have to select the past event again? https://wordpress.org/support/topic/acf-relationship-field-past-events-only-sort-of-work/ I was wondering if you knew a workaround for that.
I haven't worked with The Events Calendar for a long time.
There have surely been updates with new filters which must be a problem.
Do you happen to know which class The Events Calendar uses to pull the saved events to the page edit screen? In your codes, you remove action from Tribe__Events__Query class, and I was thinking of doing something similar if I knew which class they use to pull the saved events to the page edit screen. I looked through their list, but they have so many classes that I just couldn't find the right one. https://docs.theeventscalendar.com/reference/classes/
This seems to work for me.
add_filter('acf/fields/relationship/query/name=featured_event', 'pull_past_events', 10, 3);
add_filter('acf/load_value/name=featured_event', 'pull_past_events', 10, 3);
function pull_past_events($x, $y, $z)
{
if (class_exists('Tribe__Events__Query')) {
remove_action('pre_get_posts', array('Tribe__Events__Query', 'pre_get_posts'), 50);
}
return $x;
}
@myicicle thanks for your response, i updated the gist
For anybody trying to use this snippet, there is an extra closing parenthesis on line 2. It should be:
add_filter( 'acf/fields/relationship/query/key=field_59006ee8b9a7b', 'bea_acf_relationship', 10, 3 );
https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/#usage