1. Home
  2. Docs
  3. Filters & Hooks
  4. How to access a single custom URI?

How to access a single custom URI?

Below you can find a sample function that returns the custom URI (false if no custom URI is assigned to the post or term):

function pm_get_custom_uri($id, $is_term = false) {
	global $permalink_manager_uris;

	$permalink_manager_uris = (!is_array($permalink_manager_uris)) ? array() : $permalink_manager_uris;

	// Get the custom URI assigned to selected post
	if(!$is_term && !empty($permalink_manager_uris[$id])) {
		$custom_uri = $permalink_manager_uris[$id];
	} else if(!empty($permalink_manager_uris["tax-{$id}"])) {
		$custom_uri = $permalink_manager_uris["tax-{$id}"];
	} else {
		$custom_uri = false;
	}

	return $custom_uri;
}

// Get the custom URI assigned to post with ID #82
$custom_uri = pm_get_custom_uri(82);

// Get the custom URI assigned to term with ID #54
$custom_uri = pm_get_custom_uri(54, true);
Was this article helpful to you? Yes No