Skip Navigation

[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 6 years, 5 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.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#585541

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.

Can this be done and if so how?

Many thanks!

#585772

Sorted - should have looked at the documentation a bit closer, sorry.

[cred_field field='rescue-name-dog' post='dog' value='[wpv-user field="nickname"]' urlparam='' readonly='true' class='form-control' output='bootstrap']

Has done the trick, and I'll use a bit if CSS to hide the DIV containing that field

#585775

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Liam,

Great to hear that you were able to solve this issue 🙂 Have a great day ahead.

Thank you for sharing the solution with our community.

#586100
user_and_custom_fields_search.jpg

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.

Thanks again 🙂

#586235

Done a bit more digging and found this post from a few years ago which seems to be a way around it for a "normal" view at least...

https://toolset.com/forums/topic/parametric-search-by-author/

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.

Thanks again ????

#586579

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Yes, the above solution should work. You can give it a try and let me know if there is any issue and I will be happy to help you.

Thank you

#586868

Hi Noman,

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.

Thanks again 🙂

#587017

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Liam,

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:

$users = get_users(); 

To:

$users = get_users(role=subscriber);

For more details: https://codex.wordpress.org/Function_Reference/get_users

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.

For more details: https://codex.wordpress.org/Function_Reference/count_user_posts

Thank you

#587116

Hi again,

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 🙂

#587136

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Liam,

Please update the following code in your theme’s functions.php file:

From:

 $out .= '<option value="' . $user->ID . '">' . $user->display_name . '</a>';

To:

$out .= '<option value="' . $user->ID . '">' . $user->display_name .'('.count_user_posts( $user->ID , "book"  ).')</a>';

Replace book to your cpt slug in above code.

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/

Thank you

#587258

Hi,

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.

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