Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › How to add image source into a custom field?
- This topic has 15 replies, 2 voices, and was last updated 5 years, 1 month ago by
Ernest Marcinko.
-
AuthorPosts
-
March 26, 2021 at 4:17 am #32334
codigo3net85
ParticipantHello, im contacting you to know how to add image source a custom field. How to get the information.
Im using YITH Mult Vendor / marketplace plugin, each vendor can upload an AVATAR (like logo) for their stores. I need to know how to make that the image be loaded that avatar the shop vendor uploaded and be shown in Ajax Search Pro.In Ajax Search Pro the instance is: Tiendas
Here you can see in frontend my tests https://www.voydecompras.mx/stores/
Also i want to know how to make when i select in a search settings option a category or a tag to show all of the Stores that are related to those categories / tags selected. For example, if i select FLORES category, will show only Stores that are related to Categorie Flores.
I hope i have explained myself correctly.
Thank you.March 26, 2021 at 11:07 am #32346Ernest Marcinko
KeymasterHi,
It is a tough one, the image is probably not stored as term meta. I tried various different fields, but they were all empty. Let me know if there is an API for the Yith vendors plugin – namely a function which can return the image URL based on the vendor ID. I can then suggest a possible custom code to parse the image.
March 27, 2021 at 12:17 pm #32376codigo3net85
ParticipantHello Ernst!
YITH Multi Vendor plugin has no API =(Uff.. I’m already regretting buying the YITH Multi Vendor plugin. It is lack of tons of things.
Thank you.
March 29, 2021 at 9:33 am #32387Ernest Marcinko
KeymasterThat’s a shame. Try asking their support, they might be able to suggest something, I’m sure there is a way to get those images by the the taxonomy term IDs easily.
April 1, 2021 at 11:39 am #32499codigo3net85
ParticipantHello Ernest! I contacted YITH support about how to get avatar image from a Vendor from YITH Multivendor Store plugin.
Here is what they told me:
Hi Daniel,
thanks for contacting us. The plugin can use two type of avatar: Owner Avatar or Custom avatar and you can use this code to get it:wp_get_attachment_image( $vendor->avatar, apply_filters( 'yith_wcmv_get_avatar_size', YITH_Vendors()->get_image_size( 'gravatar' ) ) ); OR get_avatar( $vendor->owner, get_option( 'yith_vendors_gravatar_image_size', '62' ) );If you need other kind of information about that feel free to contact me again.
Have a nice day
Andrea GrilloCould you please help me to know how to “convert” this codes they gave me to a readable way for Ajax Searc Pro so it can get the Avatar Image please?
Thank you!
April 1, 2021 at 1:02 pm #32504Ernest Marcinko
KeymasterThat looks great, but still a bit of information is missing.
How do we get the $vendor object by the taxonomy term ID? Once we got that, it should get very easy.
April 2, 2021 at 5:11 pm #32535codigo3net85
ParticipantHello! Here is what YITH support told me about how to get $vendor
Hi Daniel,
you can use this:$vendor = yith_get_vendor( $term_id, ‘vendor’ );
and in add you can check if this is a valid vendor with this method
$vendor->is_valid()
Is this enough Ernest to get image from vendor and be shown in your ASP plugin?
ThanksApril 3, 2021 at 10:34 am #32544Ernest Marcinko
KeymasterThat sounds perfect!
Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter('asp_results', 'asp_results_add_custom_image', 10, 1); function asp_results_add_custom_image($results) { foreach ( $results as $k => &$r ) { if ( isset($r->taxonomy) ) { $vendor = yith_get_vendor( $r->id, 'vendor' ); $r->image = wp_get_attachment_image_src( $vendor->avatar, apply_filters( 'yith_wcmv_get_avatar_size', YITH_Vendors()->get_image_size( 'gravatar' ) ) ); } } return $results; }If all the code they mentioned was right, this should very likely work.
-
This reply was modified 5 years, 2 months ago by
Ernest Marcinko.
April 3, 2021 at 12:39 pm #32548codigo3net85
ParticipantHello! Thank you for your respose and your code!
But, i dont know if im missing something, i dont know if i need to modify anything else in the ASP settings. I already added your code in my child theme functions.php and check what happens, i recorded a video for you so you can see it:https://www.awesomescreenshot.com/video/3262819?key=18580192a1328262794efe4e02254acd
In few words, after adding the code in functions.php no results are found in ASP, if i remove the code, results appears again (without image of course).
Any advice for this?
Thanks!April 3, 2021 at 12:41 pm #32550Ernest Marcinko
KeymasterTry this variation, maybe this one:
add_filter('asp_results', 'asp_results_add_custom_image', 10, 1); function asp_results_add_custom_image($results) { foreach ( $results as $k => &$r ) { if ( isset($r->taxonomy) ) { $vendor = yith_get_vendor( $r->id, 'vendor' ); $r->image = wp_get_attachment_image_src( $vendor->avatar, apply_filters( 'yith_wcmv_get_avatar_size', YITH_Vendors()->get_image_size( 'gravatar' ) ) ); } } return $results; }April 3, 2021 at 12:43 pm #32551codigo3net85
ParticipantWow! thanks for your mega fast response!
Now im getting blank images, see attached screenshot pleaseApril 3, 2021 at 12:54 pm #32553Ernest Marcinko
KeymasterTough one, maybe this one:
add_filter('asp_results', 'asp_results_add_custom_image', 10, 1); function asp_results_add_custom_image($results) { foreach ( $results as $k => &$r ) { if ( isset($r->taxonomy) ) { $vendor = yith_get_vendor( $r->id, 'vendor' ); $im = wp_get_attachment_image_src( $vendor->avatar, apply_filters( 'yith_wcmv_get_avatar_size', YITH_Vendors()->get_image_size( 'gravatar' ) ) ); $r->image = isset($im[0]) ? $im[0] : $r->image; } } return $results; }If this does not work, then I don’t know what the issue could be.
April 3, 2021 at 1:03 pm #32554codigo3net85
ParticipantWOW! working great!!! now i see vendors avatar in ASP results!! THAAAAAANK YOU!!!!!! see attached image.
Taking advantage of the ticket, one more question. Why if in the settings search i select any category im always getting the same results? no changes, im always getting the same vendors results, check this video please:
https://www.awesomescreenshot.com/video/3262915?key=8d5b4cdc5c7d23f7a1d11d03dfb83432Any advice? Thanks
April 6, 2021 at 9:53 am #32569Ernest Marcinko
KeymasterBecause on the screenshot the results are taxonomy terms – and taxonomy terms can not be filtered by taxonomy terms, only post type results can be affected by taxonomy term filters.
April 6, 2021 at 7:12 pm #32582codigo3net85
ParticipantAh! ok! i got it.
Ernest, thanks a lot for your time and help!Thank you!
-
This reply was modified 5 years, 2 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.