Skip Navigation

[Resolved] dropdown of authors to filter posts

This support ticket is created 2 years, 7 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.

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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 2 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2164567

Hi,
I'm trying to add dropdown of authors to filter my posts on this page:
hidden link
I've tried many solutions. This is the last I tried to use:
https://toolset.com/forums/topic/parametric-search-by-author/
But I still do something wrong.
Could you please tell what where I make the mistake?
Regards,
Piotr

#2165317

Hello,

I have tried the solution you mentioned above:
https://toolset.com/forums/topic/parametric-search-by-author/#post-120197

It works fine in my localhost. there might be a cache problem in your website, if you are using any cache plugin, please try to clear the cache and test again, if you need more assistance for it, please provide your website credentials in below private message box

#2165617

Hi,
I'm writing this message, because I'm not sure if the last one have been send.
I've manage to display the results of filtering by author, but there are still some issues:
- the results display in wrong place, under the filter:
hidden link
- after clicking submit button (FILTRU) the dropdown shows the first option (autor dzieła) instead of the chosen author
- the dropdown shows the list of all authors instead of only available options for the input, also after filtering by other parameres (e.g. color)
Thanks you for your help.
Regards,
Piotr

#2167601

Thanks for the details, I have done below modifications in your website:
1) Edit theme file "functions.php", lines 73~91, replace the PHP codes as below:

/*filtr po autorze*/
 
add_shortcode("list-of-authors", "list_of_authors");
function list_of_authors() {
  $out = '<option value="">autor dzieła</option>';
  $users = get_users();
  $author_filter = '';
  if(isset($_GET['author-filter'])){
      $author_filter = $_GET['author-filter'];
  }
  foreach ($users as $user) {
    $selected = '';
    if($author_filter == $user->ID){
        $selected = ' selected';
    }
    $out .= '<option value="' . $user->ID . '"' . $selected . '>' . $user->display_name . '</a>';
  }
  return $out;
}

You can follow WP document to customize the user query:
https://developer.wordpress.org/reference/classes/wp_user_query/

2) Edit WordPress archive "dziela-arch":
a) In section "Query Filter", add a filter:
Select posts with the author's id determined by the URL parameter "author-filter" eg. yoursite/page-with-this-view/?author-filter=1
b) In section "Search and Pagination", line 12, display above shortcode:

<select name="author-filter" class="wpcf-form-select form-select select">[list-of-authors]</select>

Please test again, check if it is fixed, thanks

#2167759

Thank you for your help. It looks great now.
But still the the dropdown shows the list of all users (also admins), not only authors, who have published their post.
Also after selecting one color in filters, the dropdown displays long list of all authors, not only authors who have published their post in selected color. How can I change this?
Regards,
Agnieszka

#2168537

As I mentioned above:

You can follow WP document to customize the user query

For example, replace this line from:
$users = get_users();

To:
$users = get_users(array( 'role' => 'Author' ));

More help:
https://developer.wordpress.org/reference/classes/wp_user_query/#user-role-parameter

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