Support » Developing with WordPress » Help with syntax problem for get_image_with_alt

  • wyclef

    (@wyclef)


    What is wrong with my syntax on the following line? Trying to pull a random quote, the title and author both work but am having trouble with the get_image_with_alt line.

    $quote .= get_image_with_alt('.$rows[$i]['cover'].', get_the_ID(), '');

    The full function

    function getQuote() {
    if(get_field('books', 34)) {
            $rows = get_field('books', 34);
            $row_count = count($rows);
            $i = rand(0, $row_count - 1);
    
            echo $rows[$i]['sub_field_name'];
    
            $quote .= '<blockquote>';
            $quote .= get_image_with_alt('.$rows[$i]['cover'].', get_the_ID(), '');
            $quote .= '<div class="quote-holder">';
            $quote .= '<q>“'.$rows[$i]['title'].'”</q>';
            $quote .= '<cite>— '.$rows[$i]['author'].'</cite>';
            $quote .= '</div>';
            $quote .= '</blockquote>';
    
        }
        return $quote;
    }
    • This topic was modified 2 months ago by wyclef.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Joy

    (@joyously)

    You have nested single quotes when you shouldn’t even have quotes around the variable name.

    Moderator bcworkz

    (@bcworkz)

    ^^^ Nor the . dot concatenation operators. We don’t know what the $rows data structure contains, nor what get_image_with_alt() is expecting as a parameter, so there still may be other issues, but the outer quotes and dot operators certainly do not belong in the way you’ve used them.

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