I am trying to write a function that will allow me to specify a post ID and a blog ID, and then have it return the permalink and title of the blog post.
I need this to be efficient because the function will be used in a foreach loop that could cause the function to run upwards of 50 times.
Any ideas?
That sounds pretty simple.
Use: http://codex.wordpress.org/Function_Reference/switch_to_blog
To go back use:
This allows you to switch from site to site.
Then: http://codex.wordpress.org/Function_Reference/get_permalink
My assumptions are that you have both the Blog ID and the Post ID.
If that’s the case – using those two functions should solve your problem.
As per the suggestion above, I’ve gone for this:
where
$recent_across_network
is a list of recent posts from across a multisite network, cached using the Transients API. There’s a related tutorial here.You could equally do:
instead of
switch_to_blog()
/restore_current_blog()
– not sure which is more efficient?