HTML in custom description field

Home Forums Product Support Forums Ajax Search Pro for WordPress Support HTML in custom description field

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 5 years, 2 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #20687
    jan
    jan
    Participant

    Hi there and thanks for this great plugin.

    I’ve just enabled user search and activated a custom meta field in the descriptionfield.
    When searching a user now, everything works fine, but the result is listed with html tags saved to the meta field, like <p> and tags.
    Can this be avoided?

    Also, would it be possible to replace the image with another user_meta field?

    Thanks & Regards,
    Jan

    #20688
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Jan,

    I just tested the advanced description field for users, but it works with HTML tags on my end: https://i.imgur.com/qgQOsdM.png
    Make sure you have the latest release installed (4.14.5) and that there are no unclosed tags there in the content. That should hopefully do the trick.

    With a custom code it should be possible to get the user image from a custom field as well. Add this custom code to the functions.php in your theme/child theme directory (copy from line 3 only!). Before editing, please make sure to have a full site back-up just in case!

    Change the $field variable to the user meta field containing the image URL.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #20689
    jan
    jan
    Participant

    Hi Ernest,

    thanks for the quick reply. The image code works perfectly 🙂

    I’m trying to get rid of the HTML in the results, not include it. The HTML displayed includes the p and strong tags, which makes it look bad, especially as somehow the global CSS for the p tags is applied, including font size, family, etc. So the result is different from all other results, which looks ugly.

    Thanks & Regards,
    Jan

    #20691
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Jan,

    I see what you mean now, you want to clear the tags from a custom field, that was included via the advanced description field. That is indeed not cleared on purpose, so that anything could be included via the custom fields.
    Instead of the previous code, use this one, it is basically the same, except for one line, that will try to clear any tags within the content.

    add_filter( 'asp_results', 'asp_get_custom_cf_image', 10, 1 );
    function asp_get_custom_cf_image( $results ) {
    	$field = 'user-image-url'; // Enter the user meta field containing the image
    	foreach ($results as $k=>&$r) {
    		if ( $r->content_type == 'user' ) {
                            $r->content = wd_strip_tags_ws($r->content);
    			$img = get_user_meta($r->id, $field, true);
    			if ( !is_wp_error($img) && !empty($img) )
    				$r->image = $img;
    		}
    	}
    	return $results;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #20692
    jan
    jan
    Participant

    Perfect. Works as it should.
    Many thanks for your help.

    #20693
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.