Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Show custom field "auteur" as author
- This topic has 5 replies, 2 voices, and was last updated 5 years, 9 months ago by
tim.
-
AuthorPosts
-
August 17, 2020 at 10:09 pm #29020
tim
ParticipantHi Ernesto
5 years ago (time flies 😉 ) you helped me with a modification of your plugin. I needed the following:
In the searchresults I would like to show the authors (a custom field “auteur”) below the title (not the author according wordpress, but a custom field). Any ideas how I can achieve this?
You send me this code, which worked perfect:
$authors = get_the_terms( $post_id, "auteur" ); $author_names = array(); if ( is_array($authors) ) { foreach ($authors as $a) { $author_names[] = $a->name; } $author = implode(" | ", $author_names); } return $author; }But suddenly it doesn’t work anymore. I’ve checked functions.php and the code is still there.
Do you have any ideas what could be the problem?
Thanks!
Tim
August 17, 2020 at 10:30 pm #29021tim
ParticipantYou cannot access this content.
August 18, 2020 at 10:22 am #29030Ernest Marcinko
KeymasterHi Tim,
Some filters have been changed in the most recent releases. Please try this code instead of the old one:
add_filter( 'asp_results', 'asp_author_from_cf', 10, 1); function asp_author_from_cf($results) { foreach ( $results as $k => &$r ) { $authors = get_the_terms( $post_id, "auteur" ); $author_names = array(); if ( is_array($authors) ) { foreach ($authors as $a) { $author_names[] = $a->name; } $r->author = implode(" | ", $author_names); } } return $results; }it should do the trick.
August 18, 2020 at 9:28 pm #29037tim
ParticipantHi Ernest
Thanks for the fast reply; but alas it is not working (see attachement).
Any ideas?
Thanks!
Tim
August 19, 2020 at 9:12 am #29052Ernest Marcinko
KeymasterHi,
Sorry, there was a mistake in the code indeed, I have corrected it via FTP, it is all right now:
add_filter( 'asp_results', 'asp_author_from_cf', 10, 1); function asp_author_from_cf($results) { foreach ( $results as $k => &$r ) { $authors = get_the_terms( $r->id, "auteur" ); $author_names = array(); if ( is_array($authors) && count($authors) > 0 ) { foreach ($authors as $a) { $author_names[] = $a->name; } $r->author = implode(" | ", $author_names); } } return $results; }August 19, 2020 at 8:41 pm #29069tim
ParticipantHi Ernest
Great! Works like a charm ;).
Thanks!
Tim
-
AuthorPosts
- The topic ‘Show custom field "auteur" as author’ is closed to new replies.