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

Checklist Field Displays as Array

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

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #5602
    neilgeeneilgee
    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 MarcinkoErnest 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.

    #5614
    neilgeeneilgee
    Participant
    #5617
    Ernest MarcinkoErnest Marcinko
    Keymaster

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

    #5683
    neilgeeneilgee
    Participant

    Hi Ernest,

    I got a function that can output the array –
    [code]$checkboxes = get_field(‘my_checkbox_list’);
    if( $checkboxes ){

    $checkbox_string = implode(‘, ‘, $checkboxes);
    echo ‘ – ‘ . $checkbox_string;

    }[/code]
    So now how can I hook into Search results.

    Thanks
    Neil

    • This reply was modified 10 years, 9 months ago by neilgeeneilgee.
    #5690
    Ernest MarcinkoErnest 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:

    [php]
    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;
    }
    [/php]

    Hopefully it will work.

    #5692
    neilgeeneilgee
    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 10 years, 9 months ago by neilgeeneilgee.
    #5694
    Ernest MarcinkoErnest 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:

    [php]
    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;
    }
    [/php]

    • This reply was modified 10 years, 9 months ago by Ernest MarcinkoErnest Marcinko. Reason: fix
    #5845
    neilgeeneilgee
    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 MarcinkoErnest Marcinko
    Keymaster

    You are welcome!

    Indeed, I made a syntax error there.

    For future reference the correct code:

    [php]
    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;
    }
    [/php]

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.