This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Show custom field "auteur" as author

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Show custom field "auteur" as author

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #29020
    timtim
    Participant

    Hi 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

    #29021
    timtim
    Participant

    You cannot access this content.

    #29030
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi 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.

    #29037
    timtim
    Participant

    Hi Ernest

    Thanks for the fast reply; but alas it is not working (see attachement).

    Any ideas?

    Thanks!

    Tim

    #29052
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    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; 
    }
    #29069
    timtim
    Participant

    Hi Ernest

    Great! Works like a charm ;).

    Thanks!

    Tim

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Show custom field "auteur" as author’ is closed to new replies.