Can I pass dynamically to shortcode attributes like as the following example shows
[ authoorsposts author = get_the_author_id(); ]
Can I pass dynamically to shortcode attributes like as the following example shows
[ authoorsposts author = get_the_author_id(); ]
Not quite like that, but you can achieve the same result if you use a pre-defined value or argument in your shortcode to act as a "flag":
[authoorsposts author="post"]
...then in your handler:
function wpse_209684_author( $atts ) {
if ( ! empty( $atts['author'] ) ) {
$author = $atts['author'];
if ( $author === 'post' ) // Our flag, make $author the current post author
$author = get_the_author_id();
else // Otherwise just accept a hardcoded author ID
$author = absint( $author );
}
}
You could access the author object inside the shortcode function:
$author = get_the_author();
// access ID of author object like $author->ID
Since shortcodes are added in the content, your Php code would be escaped and won't execute.