PHP functions
SleekRank defines global PHP functions for its page groups, so a theme or plugin
reads them without knowing how SleekRank stores them. They exist only while
SleekRank is active, so guard calls with function_exists() in code that can
run without it. Its hooks, WP-CLI commands and REST operations are listed in the
generated references: hooks,
CLI and REST.
Page groups are kept in SleekRank’s own table. Each is answered as its id,
name, slug and status, followed by its configuration: urlPattern,
basePageId, dataSources, mappings, sitemapEnabled, sitemapPriority and
sitemapChangefreq. A data source’s token is never answered.
Functions
sleek_rank_get_page_groups( int $limit = -1, int $offset = 0 ): array: The page groups in any status but trash, newest first;-1returns all of them.sleek_rank_get_page_group( int $id ): ?array: The page group with this id, ornull.sleek_rank_get_page_group_by_slug( string $slug ): ?array: The page group with this slug, ornull.sleek_rank_create_page_group( array $data ): int: Creates a page group from itsname,slug,status(publishordraft) and configuration, and returns its id.basePageIdis required. Throws anExceptionwithout one, for a URL pattern without exactly one{slug}, or when it cannot be stored.sleek_rank_update_page_group( int $id, array $data ): bool: Changes the name, slug and status where$datanames them and merges the other fields into the configuration. Returnsfalsewhen there is no such page group.
Example
if (function_exists('sleek_rank_get_page_groups')) {
$id = sleek_rank_create_page_group([
'name' => 'Cities',
'basePageId' => 12,
'urlPattern' => 'cities/{slug}',
]);
sleek_rank_update_page_group($id, ['sitemapPriority' => 0.8]);
}