Relational custom field

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 year, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #39253

    I have an issue with relational custom fields in search results:
    The FIRST form([wd_asp id=2]) on this page searchs inside “reparti” post type. The single “Reparti” post has a custom field called “sedi”: it is a relational custom field nested inside the field “informazioni_generali”.
    In the avanced options I’ve set “Advanced Title Field” in this way: {titlefield} Sede: {informazioni_generali_sede}, trying to show in the results the title of “sede” but nothing happen. It works with simple fields(for example it works with {informazioni_generali_ubicazione}) but not with relational field.
    To test it visit this page and type in the first form “Cardiologia”, you will see the results from “reparti” post type and after the label “Sedi:” nothing.
    How can I print the title of a relational custom field?

    Waiting for a feedback
    best regards

    Ernest Marcinko
    Ernest Marcinko


    Relational and object storage fields will not work this way, as those have to be queried exactly by structure in a loop or a single post environment.

    The only way to print this data is to use custom code, to fetch all the needed information and add it to the content field, fetched on demand exactly as needed. I am not sure about your exact field setup, but via using the asp_results hook, this could be a potential way of getting the field values:

    add_filter('asp_results', 'asp_fetch_acf_relationship', 10, 1);
    function asp_fetch_acf_relationship($results) {
        $relationship_field_name = 'informazioni_generali';
        $field_name = 'sedi';
        // ----------------------------------------------------------------
        if ( function_exists('get_field') ) {
    		foreach ( $results as &$r ) {
    		   $items = get_field($relationship_field_name, $r->id);
    		   if ( is_array($items) ) {
    			   foreach ($items as $item) {
    				  if ( isset($item->ID) ) {
    					  $custom_field = get_field( $field_name, $item->ID );
    					  $r->content .= $custom_field;
        return $results;

    But once again this is just a possible sample, it highly depends on the field structure.

    Ernest Marcinko

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

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

You must be logged in to reply to this topic.