/** * Load the content type id on a post types. * * @param string $content_type_id * * @return string */ function papi_load_page_type_id($content_type_id = '') { $key = papi_get_page_type_key(); $post_id = papi_get_post_id(); $post_type = papi_get_post_type($post_id); // If we have a post id we can load the content type id // from the post. if ($post_id > 0) { $meta_value = get_post_meta($post_id, $key, true); $content_type_id = empty($meta_value) ? '' : $meta_value; } // Try to fetch the content type id from `page_type` // query string. if (empty($content_type_id)) { $content_type_id = papi_get_qs('page_type'); } // When using `only_page_type` filter we need to fetch the value since it // maybe not always saved in the database. if (empty($content_type_id)) { $content_type_id = papi_filter_settings_only_page_type($post_type); } // Load right content type from the parent post id. if (empty($content_type_id)) { $meta_value = get_post_meta(papi_get_parent_post_id(), $key, true); $content_type_id = empty($meta_value) ? '' : $meta_value; } // Load content type id from the container if it exists. if (empty($content_type_id)) { $key = sprintf('content_type_id.%s', $post_type); if (papi()->exists($key)) { return papi()->make($key); } } return $content_type_id; }
/** * Get page type id. * * @param int $post_id * * @return string */ function papi_get_page_type_id($post_id = 0) { $post_id = papi_get_post_id($post_id); $key = papi_get_page_type_key(); $page_type = ''; if ($post_id !== 0) { $meta_value = get_post_meta($post_id, $key, true); $page_type = empty($meta_value) ? '' : $meta_value; } if (empty($page_type)) { $page_type = str_replace('papi/', '', papi_get_qs('page_type')); } if (empty($page_type)) { $page_type = papi_get_sanitized_post(papi_get_page_type_key()); } // Load right page type from a post query string if (empty($page_type)) { $meta_value = get_post_meta(papi_get_parent_post_id(), $key, true); $page_type = empty($meta_value) ? '' : $meta_value; } // Load page type id from the container if it exists or // load it from `papi_get_all_page_types`. if (empty($page_type)) { $post_type = papi_get_post_type(); $load_once = papi_filter_core_load_one_type_on(); $collection_key = 'core.page_type.' . $post_type; if (in_array($post_type, $load_once)) { if (papi()->exists($collection_key)) { return papi()->make($collection_key); } if ($page_types = papi_get_all_page_types(false, $post_type)) { return $page_types[0]->get_id(); } } } return $page_type; }
/** * Load the entry type id on a post types. * * @param string $entry_type_id * * @return string */ function papi_load_page_type_id($entry_type_id = '') { $key = papi_get_page_type_key(); $post_id = papi_get_post_id(); $post_type = papi_get_post_type($post_id); // Try to load the entry type id from only page type filter. if (empty($entry_type_id)) { $entry_type_id = papi_filter_settings_only_page_type($post_type); } // If we have a post id we can load the entry type id from the post. if (empty($entry_type_id) && $post_id > 0) { $meta_value = get_post_meta($post_id, $key, true); $entry_type_id = empty($meta_value) ? '' : $meta_value; } // Try to fetch the entry type id from `page_type` query string. if (empty($entry_type_id)) { $entry_type_id = papi_get_qs('page_type'); } // Load right entry type from the parent post id. if (empty($entry_type_id)) { $meta_value = get_post_meta(papi_get_parent_post_id(), $key, true); $entry_type_id = empty($meta_value) ? '' : $meta_value; } // Try to load the entry type from all page types and check // if only one exists of that post type. // // The same as only page type filter but without the filter. if (empty($entry_type_id)) { $key = sprintf('entry_type_id.post_type.%s', $post_type); if (papi()->exists($key)) { return papi()->make($key); } $entries = papi_get_all_page_types($post_type); if (count($entries) === 1) { $entry_type_id = $entries[0]->get_id(); papi()->bind($key, $entry_type_id); } } return $entry_type_id; }