I am setting up "user profiles" on the author archive pages. I am using a shortcode to display the user's info, including custom fields, and have been able to do so successfully for the most part.
Now I and am trying to display the user's posts in a View on the author page. I imagine it is the View filter I need to be working on, but I can't get it to display based on the user ID.
<b>Documentation</b>
Here is where I got the shortcode to display the user's info: https://toolset.com/forums/topic/author-page-template/
I think I could do this if I could filter the View by the [get_user_id] shortcode.
<b>Link</b>
Here is an author page: hidden link
It should show this user's posts in the View.
I have a different shortcode you can use to get the ID of the current author archive User:
function get_author_id_in_archive_func($atts) {
return get_the_author_meta('ID');
}
add_shortcode("get_author_id_in_archive", "get_author_id_in_archive_func");
Then you can configure your View to filter by post author set by a shortcode attribute like "author", and the View shortcode will look like this:
[wpv-view name="your-view-slug" author="[get_author_id_in_archive]"]
Be sure to register get_author_id_in_archive in Toolset > Settings > Front-end Content > Third party shortcode arguments.
It worked! Kind of... Something seems to be wrong with that function, or I didn't set it up correctly.
I added the function to my functions.php file, then setup the View filter the way you said, and registered the shortcode.
But when I setup the View with the [get_author_id_in_archive] shortcode it didn't work. When I used the other one I had setup in its place, [get_user_id], that one did work, so, huzzah!
Here is the other function, not sure why this one worked and the new one didn't:
function get_user_id() {
$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
return $author->ID;
}
add_shortcode( 'get_user_id', 'get_user_id' );
Either way, thanks!