Home Forums Add-ons Flexible Content Field have_rows is returning false


have_rows is returning false

  • Hi,

    I’m using ACF and Algolia, it seems to do what I’m expecting, except for one thing :

    the have_rows is returning false even tho there are rows, as you can see, as it doesn’t pass the have_rows : true, it goes to the false statement where I assign the field ($blockContentField) to $pageContent and then $pageContent is sent to algolia. I’m checking algolia and there is content. Not sure why have_rows return false at first place, it should be true.

    I have seen other posts on the forum talking about this issue, but none with a real fixe at least none are working in my case. I’m using the flexible content and in the doc it says clearly to use have_rows.

    Thank you

    function algolia_post_to_record(WP_Post $post) {
        $tags = array_map(function (WP_Term $term) {
            return $term->name;
        }, wp_get_post_terms($post->ID, 'tags'));
        $fields = array_map(function (WP_Term $term) {
            return $term->name;
        }, wp_get_post_terms($post->ID, 'field'));
        $sectors = array_map(function (WP_Term $term) {
            return $term->name;
        }, wp_get_post_terms($post->ID, 'sector'));
        $pageContent = '';
        $blockContentField = get_field('content_block', $post->ID );
        if( have_rows($blockContentField) ):
           $pageContent = 'item';
        else :
            // no rows found
            $pageContent = $blockContentField;
        return [
            'objectID' => implode('#', [$post->post_type, $post->ID]),
            'title' => $post->post_title,
            'author' => [
                'id' => $post->post_author,
                'name' => get_user_by('ID', $post->post_author)->display_name,
            'excerpt' => $post->post_excerpt,
            'content' => strip_tags($post->post_content),
            'tags' => $tags,
            'fields' => $fields,
            'sectors' => $sectors,
            'url' => get_post_permalink($post->ID),
            // 'pageContent' => get_field('content_block', $post->ID ),
            'pageContent' => $pageContent,
    add_filter('post_to_record', 'algolia_post_to_record');

    I’m using last version of ACF

  • have_rows() is looking for a field name. You are using the return array of the field instead.

    // use this
    if (have_rows('content_block', $post->ID)):
    // or this
    if (!empty($blockContentField)):
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.