1. Home
  2. Docs
  3. Filters & Hooks
  4. How to access the custom URIs or redirects array with PHP?

How to access the custom URIs or redirects array with PHP?

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

How can we help?

Wait!!! Before you go...

Still not convinced? Use following discount code during Gumroad checkout and get 10% off!

BLOG

If you have any questions or need further information, please feel free to contact me via email: