Skip Navigation

[Gelöst] Display posts on author archive that belong to that author

This support ticket is created vor 5 Jahre. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 Antworten, has 2 Stimmen.

Last updated by Waqar vor 5 Jahre.

Assisted by: Waqar.

Author
Artikel
#1224845

Hi there,

I'm trying to create a view that I can add to author archive pages (via Elementor) that will output posts according to the author the archive belongs to.

See here: hidden link
And here: hidden link

Currently both author pages show all the "project" posts (project 1, project 2, project 3) regardless of who the author is. What I need to do is show only the pertinent author's projects on their archive.

ALTERNATIVELY (this is a long shot), I wonder if there's any way to pull post relationship content onto these project posts with Elementor's Posts widget (similar to how I have the cars listed on those author archive pages, but also including the title from a related post)... The reason I'm trying to use a View for projects is because I couldn't find any way to pull in related post content in Elementor's widgets.

Ultimately what I'm trying to do is allow users/authors to add cars to their pages, and then add projects related to a car -- then I want to list that author's projects with an indication of which car they a related to. E.g. Project 1 -- Car 1

Let me know if this makes sense, or if I can clarify anything. Thanks!!

#1225052

Waqar
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Nick,

Thank you for contacting us and I'll be happy to assist.

To filter your "projects" posts view, to only show projects from the author whose author archive page is being viewed, you can follow these steps:

1. In the view's "Query Filter" section, please add a post author filter, to show only posts from the author whose ID is provided by the View shortcode attribute e.g. "author".
( screenshot: hidden link )

2. Add the following custom shortcode, in your active theme's "functions.php" file which returns the ID of the author whose author archive page is being viewed:


function get_author_id_in_archive_func($atts) {
  $author_id = 0;
  if (is_author()){
    $author = get_queried_object();
    $author_id = $author->ID;
  }
  return $author_id;
}
add_shortcode("get_author_id_in_archive", "get_author_id_in_archive_func");

3. In your Elementor template, you can then load this view with a shortcode attribute "author", like this:
( it can be added in a regular text editor widget )


[wpv-view name="slug-of-the-view" author="[get_author_id_in_archive]"]

Note: you'll replace "slug-of-the-view" with the actual slug of your view.

Next, when you'll have the correct list of projects on the author archive page, you can use a nested view inside the projects post view, to show information from the related cars, as explained in this guide:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1225333

Hey Waqar, thanks for the response!

Unfortunately, this doesn't appear to be working. I have it implemented on my template 3 different ways: using the Views widget in Elementor (no option for shortcode attribute though), in a text widget, and in a shortcode widget.

hidden link

Both shortcode versions don't seem to process the "[get_author_id_in_archive]" and leave the extra square bracket in the output. And none of them appear to filter out the posts by author.

I should also note that I am using Anywhere Elementor (plugin) to create the author archive template.

Any idea how we could get this working? Happy to send over admin account credentials if that helps.

Cheers!

#1225564

Waqar
Supporter

Languages: Englisch (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Nick,

Thanks for sharing the update.

Have you tested the [get_author_id_in_archive] shortcode alone, to see if it returns the ID of the current author, on the author archive page?

I would also recommend registering this shortcode's name ( 'get_author_id_in_archive' ) in the "Third-party shortcode arguments" section at WP Admin -> Toolset -> Settings -> Front-end Content and then test it inside the view's shortcode.
( screenshot: hidden link )

Note: The suggested approach works in my tests when used from inside a regular Elementor template for the author archive page. You can test this the same way, without the Anywhere Elementor plugin.

If it works without Anywhere Elementor plugin, you can consult plugin's support team, for a workaround/suggestion on how to make it process/render a shortcode within a shortcode attribute.

Please let me know how it goes.

regards,
Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.