Tribe__Events__Linked_Posts::get_linked_post_info( string $linked_post_type, array $args = array(), array|int $linked_post_ids = null )
Get Linked Post info
Contents
Parameters
- $linked_post_type
-
(string) (Required) Post type of linked post.
- $args
-
(array) (Optional) Extra WP Query args.
Default value: array()
- $linked_post_ids
-
(array|int) (Optional) Post ID(s).
Default value: null
Return
(array)
Source
File: src/Tribe/Linked_Posts.php
public function get_linked_post_info( $linked_post_type, $args = array(), $linked_post_ids = null ) {
$func_args = func_get_args();
$cache_key = $this->cache->make_key( $func_args, 'linked_post_info_' );
if ( isset( $this->cache[ $cache_key ] ) ) {
return $this->cache[ $cache_key ];
}
/**
* Whether to return all linked posts if the args actually find no linked posts.
*
* @since 4.6.22
*
* @param bool $return_all_if_none True if you want all posts returned if none
* are found (e.g. creating a drop-down).
* False if you want none returned if none are
* found (e.g. actually querying for matches).
* @param string $linked_post_type Post type of linked post.
* @param array $args WP Query args before merging with defaults.
* @param array|int $linked_post_ids Post ID(s).
*
* @return bool
*/
$return_all_if_none = (bool) apply_filters( 'tribe_events_return_all_linked_posts_if_none', false, $linked_post_type, $args, $linked_post_ids );
// Explicitly force zero results if appropriate. Necessary because passing an empty array will actually display all posts, per https://core.trac.wordpress.org/ticket/28099
if (
empty( $linked_post_ids )
&& false === $return_all_if_none
) {
$linked_post_ids = array( -1 );
}
$defaults = array(
'post_type' => $linked_post_type,
'post_status' => array(
'publish',
'draft',
'private',
'pending',
),
'order' => 'ASC',
'orderby' => 'post__in post_title',
'ignore_sticky_posts ' => true,
'nopaging' => true,
);
if ( is_array( $linked_post_ids ) ) {
$defaults['post__in'] = $linked_post_ids;
} elseif ( 0 < absint( $linked_post_ids ) ) {
$defaults['p'] = absint( $linked_post_ids );
}
$args = wp_parse_args( $args, $defaults );
/**
* The WP_Query arguments used when getting information per Linked Post.
*
* Useful if you want to add `orderby` or override existing arguments.
*
* @param array $args The WP_Query arguments.
* @param string $linked_post_type The post type key.
* @param int|array $linked_post_ids A single Linked Post ID or an array of Linked Post IDs.
*
* @return array
*/
$args = apply_filters( 'tribe_events_get_linked_post_info_args', $args, $linked_post_type, $linked_post_ids );
/**
* Filters the linked posts query allowing third-party plugins to replace it.
*
* This is an opt-out filter: to avoid The Events Calendar from running the linked posts query as it would
* normally do third parties should return anything that is not exactly `null` to replace the query and provide
* alternative linked posts.
*
* @param array $linked_posts Defaults to `null`; will be an array if another plugin did run the query.
* @param array $args An array of query arguments in the same format used to provide arguments to WP_Query.
*
*/
$linked_posts = apply_filters( 'tribe_events_linked_posts_query', null, $args );
if ( null !== $linked_posts ) {
return $linked_posts;
}
$result = new WP_Query( $args );
if ( $result->have_posts() ) {
$linked_posts = $result->posts;
} else {
$linked_posts = array();
}
$this->cache[ $cache_key ] = $linked_posts;
return $linked_posts;
}