Tribe__Events__Linked_Posts::has_linked_posts( int $post_id )
Returns whether or not there are any linked posts for the given post id
Contents
Parameters
- $post_id
-
(int) (Required) Post ID of the object
Return
(boolean)
Source
File: src/Tribe/Linked_Posts.php
public function has_linked_posts( $post_id ) {
$post_types = $this->get_linked_post_types();
$post_id_post_type = get_post_type( $post_id );
$args = array(
'p' => $post_id,
'post_type' => $post_id_post_type,
'meta_query' => array(),
);
if ( Tribe__Events__Main::POSTTYPE === $post_id_post_type ) {
// if the post type that we're looking at is an event, we'll need to find all linked post types
foreach ( $post_types as $post_type => $post_type_data ) {
$args['meta_query'][] = array(
'key' => $this->get_meta_key( $post_type ),
'compare' => 'EXISTS',
);
}
} else {
// if the post type is NOT an event post type, we just want to find the associated event posts
$args['meta_query'][] = array(
'key' => $this->get_meta_key( Tribe__Events__Main::POSTTYPE ),
'compare' => 'EXISTS',
);
}
$args['meta_query']['relation'] = 'OR';
$query = new WP_Query( $args );
/**
* Filters the results of the query to determine whether or not there are linked posts
*
* @param boolean Whether or not there are linked posts
* @param int Post ID of the post being looked at
*/
return apply_filters( 'tribe_events_has_linked_posts', $query->have_posts(), $post_id );
}
Changelog
| Version | Description |
|---|---|
| 4.2 | Introduced. |