/** * Load the entry type id on a taxonomy. * * @param string $entry_type_id * @param string $type * * @return string */ function papi_load_taxonomy_type_id($entry_type_id = '', $type = 'term') { if ($type !== 'term') { return $entry_type_id; } $key = papi_get_page_type_key(); $term_id = papi_get_term_id(); $taxonomy = papi_get_taxonomy($term_id); // Try to load the entry type id from only taxonomy type filter. if (empty($entry_type_id)) { $entry_type_id = papi_filter_settings_only_taxonomy_type($taxonomy); } // If we have a term id we can load the entry type id from the term. if (empty($entry_type_id) && $term_id > 0 && papi_supports_term_meta()) { $meta_value = get_term_meta($term_id, $key, true); $entry_type_id = empty($meta_value) ? '' : $meta_value; } // Load entry type id from the container if it exists. if (empty($entry_type_id)) { $key = sprintf('entry_type_id.taxonomy.%s', $taxonomy); if (papi()->exists($key)) { return papi()->make($key); } } return $entry_type_id; }
/** * Load the entry type id on a taxonomy. * * @param string $entry_type_id * @param string $type * * @return string */ function papi_load_taxonomy_type_id($entry_type_id = '', $type = 'term') { if ($type !== 'term') { return $entry_type_id; } $key = papi_get_page_type_key(); $term_id = papi_get_term_id(); $taxonomy = papi_get_taxonomy($term_id); // Try to load the entry type id from only taxonomy type filter. if (empty($entry_type_id)) { $entry_type_id = papi_filter_settings_only_taxonomy_type($taxonomy); } // If we have a term id we can load the entry type id from the term. if (empty($entry_type_id) && $term_id > 0 && papi_supports_term_meta()) { $meta_value = get_term_meta($term_id, $key, true); $entry_type_id = empty($meta_value) ? '' : $meta_value; } // Try to load the entry type from all taxonomy types and check // if only one exists of that post type. // // The same as only taxonomy type filter but without the filter. if (empty($entry_type_id)) { $key = sprintf('entry_type_id.taxonomy.%s', $taxonomy); if (papi()->exists($key)) { return papi()->make($key); } $entries = papi_get_all_entry_types(['args' => $taxonomy, 'mode' => 'include', 'types' => ['taxonomy']]); if (is_array($entries)) { usort($entries, function ($a, $b) { return strcmp($a->name, $b->name); }); } $entries = papi_sort_order(array_reverse($entries)); if (count($entries) === 1) { $entry_type_id = $entries[0]->get_id(); papi()->bind($key, $entry_type_id); } } return $entry_type_id; }