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
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
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
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
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
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