Checklist Field Displays as Array

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Checklist Field Displays as Array

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

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #5602
    neilgee
    neilgee
    Participant

    Hi,

    I am using ACF for a custom field for a list, it is set up as a checkbox type.
    I want to display those fields in the search so I used Advanced Description Field (default: {descriptionfield}) and set it up:

    {descriptionfield} – {my_checkbox_list}

    But when it displays it shows just Array – how can I show the array’s content?

    ( I have taken off current site – but have attached an image of how it displays)
    checklist

    #5610
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    I believe ACF runs a function through that array to display it, or uses some kind of code to parse through the array. It means that not the checkbox HTML is stored in the custom field, but some kind of array values, that are transformed into checkboxes.

    You can ask the ACF author how the checkbox array is transformed into actual HTML checkboxes, then I might be able to suggest a customization or filter function to append the transformed code to the result list. It’s probably going to be some kind of function or a small snippet from the ACF plugin code.

    Best,
    Ernest Marcinko

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


    #5614
    neilgee
    neilgee
    Participant
    #5617
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Nice! Let me know if they reply, and I will proceed from there.

    Best,
    Ernest Marcinko

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


    #5683
    neilgee
    neilgee
    Participant

    Hi Ernest,

    I got a function that can output the array –

    $checkboxes = get_field('my_checkbox_list');
    	if( $checkboxes ){
    		
    		$checkbox_string = implode(', ', $checkboxes);
    		echo ' – ' . $checkbox_string;
    		
    }

    So now how can I hook into Search results.

    Thanks
    Neil

    • This reply was modified 8 years, 8 months ago by neilgee neilgee.
    #5690
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Nice. First of all you need to change back the Advanced description field option to the default {descriptionfield} because we are doing a different solution.

    Then, I put together a filter, which parses through each result and gets the ‘my_checkbox_list’ field as per suggested on ACF support forums. Then it’s appended to the description:

    
    add_filter( 'asp_results', 'asp_checkbox_to_results', 1, 1 );
     
    asp_checkbox_to_results( $results ) {
      foreach ($results as $k=>$v) {
        // Get the field
        $checkboxes = get_field('my_checkbox_list');
        // Append if exists
        if( $checkboxes ){   
            $checkbox_string = implode(', ', $checkboxes);
            $results[$k]->content  .= " - " . $checkbox_string;
        }
      }
     
      return $results;
    }
    

    Hopefully it will work.

    Best,
    Ernest Marcinko

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


    #5692
    neilgee
    neilgee
    Participant

    Hi,
    No unfortunately didn’t work – so I set {descriptionfield} only in advanced desc. field and added function/action to functions.php but results did not show check list values – just the title field.

    • This reply was modified 8 years, 8 months ago by neilgee neilgee.
    #5694
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    If the normal description is showing, then the “if ( $checkboxes ) …” part of the code is not executed. I think the ACF get_field() function needs a post ID as well. Try this modification of their suggestion:

    
    add_filter( 'asp_results', 'asp_checkbox_to_results', 1, 1 );
    
    asp_checkbox_to_results( $results ) {
      foreach ($results as $k=>$v) {
        // Get the field
        $checkboxes = get_field('my_checkbox_list', $v->id);
        // Append if exists
        if( $checkboxes ){  
            $checkbox_string = implode(', ', $checkboxes);
            $results[$k]->content  .= " – " . $checkbox_string;
        }
      }
      
      return $results;
    }
    
    • This reply was modified 8 years, 8 months ago by Ernest Marcinko Ernest Marcinko. Reason: fix
    Best,
    Ernest Marcinko

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


    #5845
    neilgee
    neilgee
    Participant

    Apologies for the delay in getting back to you but this works great! – just had to prefix the function with function

    Many thanks

    #5847
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You are welcome!

    Indeed, I made a syntax error there.

    For future reference the correct code:

    
    add_filter( 'asp_results', 'asp_checkbox_to_results', 1, 1 );
     
    function asp_checkbox_to_results( $results ) {
      foreach ($results as $k=>$v) {
        // Get the field
        $checkboxes = get_field('my_checkbox_list', $v->id);
        // Append if exists
        if( $checkboxes ){ 
            $checkbox_string = implode(', ', $checkboxes);
            $results[$k]->content  .= " – " . $checkbox_string;
        }
      }
       
      return $results;
    }
    
    Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.