Question

I'm using the Advanced Custom Field plugin - although I'm not positive that is relevant. Nonetheless, I can't get substr() to work at all using this method:

$givchars = 5; 
$postgiv = the_sub_field('get_involved_text'); 
$modgiv = substr($postgiv, 0, $givchars); 
echo ' ' .$modgiv. ' ';

However substr() does work when I do this:

$second_query = new WP_Query( $args );
if ( $second_query->have_posts() ):
   while( $second_query->have_posts() ) : $second_query->the_post();

   $titlechars = 5; // Character Limit
   $posttitle = get_the_title();
   $modtitle = substr($posttitle, 0, $titlechars);

   $attachment_id = get_field('image');
   $size = 'customfeatins'; // (thumbnail, medium, large, full or custom size)
   $image = wp_get_attachment_image_src( $attachment_id, $size ) . 'http://placehold.it/136x90';

    echo '<article>

        <img src="' . $image[0] . '" alt="' . get_the_title() .'" width="136" height="90" />
        <h3>' . $modtitle .'</h3>
        <p class="date">' . get_the_date() .'</p>

    </article>
    ';

   endwhile;
endif;

I'm just learning WordPress and my php skills are pretty limited, am I totally overlooking something?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top