Forums › Forums › Search & Filter Pro › Use meta field for taxonomy value display
Tagged: Co-Authors Plus, post meta, taxonomy
- This topic has 36 replies, 6 voices, and was last updated 6 years, 10 months ago by Anonymous.
-
Anonymous(Private) November 27, 2015 at 4:48 pm #30908
I’m using the Co-Authors Plus plugin. I want to be able to search by author name.
Co-Authors Plus saves author information in a custom Author Taxonomy (not in the post meta). Details -> https://vip.wordpress.com/documentation/list-posts-by-a-co-author/
I successfully added this as a filter using the “Taxonomy” option in the form builder. However, on the front-end, it’s displaying the author slug, not the display name, saved as Meta Key / Name “cap-display-name”. I can access this through the “Post Meta” option on the form builder, but it doesn’t actually effect the filtering of the posts.
So my question is: Can I key the auto-generated taxonomy list to use a post meta key for displaying values?
Example live at: http://www.cs.huji.ac.il/labs/casmip/research/publications-search/
Ross Moderator(Private) December 5, 2015 at 11:05 pm #31520Hey Leo
I was just looking into something which might help you.
So it sounds like the plugin is using Taxonomies in the regular way, but to store addition info about authors its saving that across into Post Meta.
At the moment linking the two is not possible, but I’ve been looking at adding in a filter to html output of all the fields.
Its a bit tricky at the moment but I need to investigate further how this can be done effectively, so you get access to the values as well as the html – in and organised manner that can be applied to every field type.
Will take a little while before I get to develop something robust but its definitely on the todo list.
Thanks
Ross Moderator(Private) December 11, 2015 at 6:39 pm #32024Turns out this feature is almost done ๐ Want to try the dev version when its ready tonight/tomorrow?
Ross Moderator(Private) June 16, 2016 at 5:00 pm #48626Hey Davide
I think this will be possible – there is a filter that allows you to modify any field
There is a really extensive example here:
https://gist.github.com/rmorse/7b59b45a14b1ca179868To see how to change the labels of the options this one is probably your best starting point
https://support.searchandfilter.com/forums/topic/change-post-type-labels/#post-40004๐
Anonymous(Private) June 17, 2016 at 5:15 pm #48787Hi, thanks, in your example it’s explained how to change a single label (from Media to Photos), but in this case, as the case of the user that began this thread, i need to print the displayname instead of slugs, so i need to change all the labels, obviously by code, while searching taxonomy auhtor fields. Is there a way to do this (or the way is in the docs you posted me?).
Anonymous(Private) June 19, 2016 at 9:54 pm #48857I’m struggling with this one, as well. I’ve been playing around with it for a couple of hours but have yet to come up with a solution. Will keep you posted if I do!
Here’s what I’ve figured out thus far:
Co-Authors Plus stores its data in terms under the custom taxonomy of ‘author’.
Search & Filter Pro retrieves the ‘name’ field of each author:
But we don’t want this field, we want the display name.
Co-Authors Plus itself doesn’t seem to store the display name, so we’ll need to use the value of the meta “name” field to retrieve it using a process along the lines of:
$author = 'corrado.poli'; // This is the value we're returning at the moment (user login) via $input_object['name'] $user = get_user_by( 'login', $author ); // Uses user login (the value that Search & Filter Pro is returning) to fetch user meta echo 'User is ' . $user->display_name; // Returns the display name (e.g. Corrado Poli) from the user meta
Thus far I figure we need to use if ($sfid == 123 && $input_object[‘taxonomy’] == ‘author’) {} and find some way of filtering the name field and replacing it with the display name.
I’ll keep playing, but any advice from the coding wizards at Search & Filter Pro would be MUCH appreciated! ๐
Cheers me dears!
Anonymous(Private) June 19, 2016 at 11:22 pm #48858Whoops! Nope, being an idiot. Ignore what I said about input taxonomy. That was a load of old hogswash. Would help if slowed down for a second to realise just how the filter (and the plugin) worked!
Getting closer:
function filter_function_name($input_object, $sfid) { if ($input_object['name'] == '_sft_author') { global $coauthors_plus; //udpate this field before rendering foreach($input_object['options'] as $key => $option) { $user = $coauthors_plus->get_coauthor_by( 'user_nicename', $option ); $input_object['options'][$key]->label = $user->display_name; } } return $input_object; } add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);
-
AuthorPosts