[Resolved] Autocomplete a custom post field with the users nickname when using CRED
This thread is resolved. Here is a description of the problem and solution.
Problem:
Is there any sort of workaround that would allow a visitor looking at an archive to filter it via a combination of the CPT fields and / or the post author? Solution:
Similar solution here: https://toolset.com/forums/topic/parametric-search-by-author/ Relevant Documentation:
This support ticket is created 7 years 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.
The site helps with re-homing of dogs and they are added via a CRED form, I've created a custom post type with fields for age, gender etc and a parametric searchable archive but would also like this archive to be searchable by post user at the same time - from what I've read its not possible to directly mix post and user field in the same Views?
If this is the case I was thinking of working around it by creating a field called "dog post author", having this field auto completed with the users nickname when saving the form / creating the post and then adding this to the search filter - this way it looks like its searching by nickname but is actually using the auto completed post field.
Seems i was a bit keen in marking this as complete.....
My bit of code above will save the users nickname to a text / single line field but I cant find a way of showing this as a single select on the archive search 🙁 Setting the field to single select doesn't seem to save the value set in the shortcode, presumably because its not a valid option? On that basis i've tried adding the nickname as one the select options but it still wont save the value and defaults to the "not set" value
As per my original post there doesn't seem to be an out the box way of mixing author and post field searching / filtering for an archive?
Is there any sort of workaround that would allow a visitor looking at an archive to filter it via a combination of the CPT fields and / or the post author? I've attached an image that should explain it better.
Does this still work / apply to the newer versions of toolset or has a better way been found(?) - In my case the authors of the CPT are in new group, not any of the standard WP ones.
It would be really neat if there was a way of filtering the archive by users (nickname) in combination with custom fields.
It works to a fashion but doesn't really fit in with how i imagined / hoped the search would work.
I realise it may be quite an ask but is there anyway the code could be adapted to do the following?
Show only users from a certain custom user group
Display the number of post after the nickname, for example "user nickname (5)" like the other search filters
Update via Ajax when a selection is made like the rest of the search form
Have the same apearance / css styles as the auto generated filter controls shown in the screen grab from my other post.
If its too much drama / beyond the scope of the support policies then no problem, the site will still work without it but it would have made narrowing down the results a bit easier.
Show only users from a certain custom user group
>> Yes, you can show users with certain roles i.e. Administrator, Author, Subscriber etc. So that your previous code will replace from:
Display the number of post after the nickname, for example "user nickname (5)" like the other search filters
>> Yes, you can show user post count using following function.
Thanks very much for the code snippets and the codex link. The user role change works great and I sorted the styling / triggering a page update by looking at the generate page and applying the same classes to the select box.
I've look at the codex link and just cant figure it out where on the select box output it goes, try as i might it just throws up various errors and hunting around on the web for examples hasn't come up with anything.
Once again I appreciate the help, as you can tell web design and the associated technologies are not my strong point, although Toolset has done exactly what it says on the tin and has made things so much easier / better to work with 🙂
Other than that falls into Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/). So we recommend to contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/
Thanks for going the extra mile and altering the code, it seems i was quite close but had missed some quotes...
Its still not as responsive as the "proper" parametric select boxes as the post count doesn't change with the other options and it doesn't hide users with no posts but its better than not being able to search at all.
I'll mark this as solved as it works as intended even if there are some limitations.