Make post author smart action work outside The Loop

** Edit ** This was not a bug or feature request. This was my own stupidity for forgetting to include a loop in my single.php file.

This is sort of a follow-up on the post: Wp author action on single post template - Pinegrow WP - Pinegrow Community Forum

I’d also like to see the smart action work on post templates outside the loop. For example, my blog post template needs to include an author box with the author’s name, biography, and avatar image. The smart action’s function, get_the_author_meta(), works fine when called from a loop, but from a template, it needs the author passed to it by using something like “$post->post_author”

Not working

With Post Author defined:

I also noticed that the author description field isn’t listed in the dropdown, so I had to enter “description” in the custom meta field field ID.

Lastly, it looks like some of the author actions are using older the_author() functions that have been superseded by get_the_author(). It appears that the other functions like the_author_link() now just echo get_the_author_link() and may also need to be updated in Pinegrow.

My apologies if I’ve missed something obvious. It looks like the author of the original post I referenced solved his problem but never followed up in the post to tell the rest of us his solution.

@adamslowe is $post defined when the action is called? If you are using the action outside of the Loop, then of course you need to provide the author_id explicitly.

In the referenced forum post, the Loop was missing in the single template. To my understanding, the Loop is needed also when a single post is displayed, so that all post data is correctly setup by WP before the post is displayed.

I added the “description” to the dropdown.

Re the and get actions. There are tons of such functions in WP. the_ version outputs whatever the get_ version returns. In the past the_author has the second argument that returned the value when it was false. That was depreceated. That brought the function behaviour in line with the rest of the_ and get_ functions. The function itself is still good for displaying info.

1 Like

Okay, now I feel like a complete moron, I also had no loop in the template. It’s amazing the things you forget when you are used to reusing past projects, then decide to start a new one from scratch!

1 Like