Skip Navigation

[Resolved] Display posts (in a view) by user ID (for author archive layout)

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by richardG-4 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1289899

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.

#1289911

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.

#1289983

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!