function wpfc_get_latest_series_image_id($latest_series = 0) { $associations = sermon_image_plugin_get_associations(); $tt_id = absint($latest_series->term_taxonomy_id); $ID = 0; if (array_key_exists($tt_id, $associations)) { $ID = absint($associations[$tt_id]); } return $ID; }
/** * Queried Term Image ID. * * Designed to be used in archive templates including * (but not limited to) archive.php, category.php, tag.php, * taxonomy.php as well as derivatives of these templates. * * Returns an integer representing the image attachment's ID. * In the event that an image has been associated zero will * be returned. * * This function should never be called directly in any file * however it may be access in any template file via the * 'sermon-images-queried-term-image-id' filter. * * @param mixed Default value for apply_filters() to return. Unused. * @return int Image attachment's ID. * * @access private Use the 'sermon-images-queried-term-image-id' filter. * @since 0.7 */ function sermon_images_plugin_get_queried_term_image_id($default) { $filter = 'sermon-images-queried-term-image-id'; if ($filter !== current_filter()) { sermon_image_plugin_please_use_filter(__FUNCTION__, $filter); } $obj = get_queried_object(); /* Return early is we are not in a term archive. */ if (!isset($obj->term_taxonomy_id)) { trigger_error(sprintf(esc_html__('%1$s is not a property of the current queried object. This usually happens when the %2$s filter is used in an unsupported template file. This filter has been designed to work in taxonomy archives which are traditionally served by one of the following template files: category.php, tag.php or taxonomy.php. Learn more about %3$s.', 'sermon-manager'), '<code>' . esc_html__('term_taxonomy_id', 'sermon-manager') . '</code>', '<code>' . esc_html($filter) . '</code>', '<a href="http://codex.wordpress.org/Template_Hierarchy">' . esc_html('template hierarchy', 'sermon-manager') . '</a>')); return 0; } if (!sermon_image_plugin_check_taxonomy($obj->taxonomy, $filter)) { return 0; } $associations = sermon_image_plugin_get_associations(); $tt_id = absint($obj->term_taxonomy_id); $ID = 0; if (array_key_exists($tt_id, $associations)) { $ID = absint($associations[$tt_id]); } return $ID; }
/** * Cache Images * * Sets the WordPress object cache for all term images * associated to the posts in the provided array. This * function has been created to minimize queries when * using this plugins get_the_terms() style function. * * @param array Post objects. * * @access private * @since 1.1 */ function sermon_image_plugin_cache_images($posts) { $assoc = sermon_image_plugin_get_associations(); if (empty($assoc)) { return; } $tt_ids = array(); foreach ((array) $posts as $post) { if (!isset($post->ID) || !isset($post->post_type)) { continue; } $taxonomies = get_object_taxonomies($post->post_type); if (empty($taxonomies)) { continue; } foreach ($taxonomies as $taxonomy) { $the_terms = get_the_terms($post->ID, $taxonomy); foreach ((array) $the_terms as $term) { if (!isset($term->term_taxonomy_id)) { continue; } $tt_ids[] = $term->term_taxonomy_id; } } } $tt_ids = array_filter(array_unique($tt_ids)); $image_ids = array(); foreach ($tt_ids as $tt_id) { if (!isset($assoc[$tt_id])) { continue; } if (in_array($assoc[$tt_id], $image_ids)) { continue; } $image_ids[] = $assoc[$tt_id]; } if (empty($image_ids)) { return; } get_posts(array('include' => $image_ids, 'post_type' => 'attachment')); }