Is there a bug or something that prevents post author’s functions not to work in customizer selective refresh callback?
It renders fine on initial page load, but author functions don’t show after the refresh. Other functions seems to work fine.
Here is my demo callback function for selective refresh:
function refresh_callback() {
echo get_author_meta('ID'); // isn’t rendered after refresh / setting change
echo get_the_title(); // is rendered fine after refresh / setting change
}
The selective refresh request doesn’t get the whole regular WordPress request context. That is why on initial load (regular request) it works, while on AJAX partial refresh it doesn’t. In your case, the global $authordata
is not set and get_the_author_meta()
is relying on it when no user is explicitly provided.
You will need to do a little bit of work yourself:
function refresh_callback() {
// First get the current post
$current_post = get_post();
// Test if we actually have a post content (we might be in an archive context)
if ( ! empty( $current_post ) ) {
echo get_the_author_meta('ID', $current_post->post_author );
echo get_the_title( $current_post );
}
}