Skip Navigation

[Résolu] How can i filter a view based on USER selected "Post Author"

This support ticket is created Il y a 4 années et 6 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Luo Yang Il y a 4 années et 6 mois.

Assisté par: Luo Yang.

Auteur
Publications
#1625055

lien caché
Refer to screenshot.

Currently this view can be filtered by keywords BUT
I would also like it to be "filter-able" based on Post Author (ideally from a drop down of all current user names).
Is that even possible?

#1625101

Hello,

There isn't such kind of built-in feature within Toolset plugins, you might consider custom codes, for example:
1) Create a custom shortcode to output the users as a dropdown:

add_shortcode("list-of-authors", "list_of_authors");
function list_of_authors() {
	$out = '<select name="author-filter">';
	$out .= '<option value="">All Users</option>';
	$users = get_users();
	foreach ($users as $user) {
		$selection = (isset($_GET['author-filter']) ? $_GET['author-filter']: '');
		$out .= '<option ' . selected($user->ID, $selection, false) . ' value="' . $user->ID . '">' . $user->display_name . '</a>';
	}
	$out .= '</select>';
	return $out;
}

2) Put above shortcode into the custom search form:

[list-of-authors]

You can setup specific parameters in get_users() function, see WP document:
https://developer.wordpress.org/reference/functions/get_users/

#1626645

I'm not sure I understand properly how to incorporate this shortcode into the view "filters".

It doesn't necessarily HAVE to be a drop down list.
A string search box (to search and filter for part matching usernames) would also serve the purpose.

#1628503

As I mentioned above there isn't such kind of built-in feature within Toolset plugins, you can put the custom shortcode into the your view's custom search form. For example:
1) edit the post view, put that shortcode [list-of-authors] into section "Search and Pagination"
It will pass author's id as URL parameter.

2) in section "Query Filter", add a post author filter:
Select posts with the author's id determined by the URL parameter "author-filter" eg. yoursite/page-with-this-view/?author-filter=1

for the new question:
A string search box (to search and filter for part matching usernames) would also serve the purpose.

I assume you are going to filter the result by: author's name "LIKE" user's input.
No, there isn't such kind of built-in feature within Toolset Views plugin, see WP document:
https://developer.wordpress.org/reference/classes/wp_query/#author-parameters
There isn't "LIKE" comparison