• Resolved scottiescotsman

    (@scottiescotsman)


    <?php foreach ( $terms as $term ) { ?>
    <?php if substr( 'term', 0, 1 ) == ( $mo ) {
    <div class="col-md-6 align_Center">
    <?php echo $term->name; ?> <span style="color: white"><?php echo $term->count;	
    </div>
    <?php }; }; ?>

    I think this is the best way to solve my problem with the actor query

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    Is there a question?

    Thread Starter scottiescotsman

    (@scottiescotsman)

    it doesn’t work as get error sorry ??

    Moderator bcworkz

    (@bcworkz)

    I happen to know the back story to this and I still am not totally sure what your intent is. When you start a new topic, you need to assume readers know nothing of your previous questions or what project you are working on. Providing links to other posts for context would be the minimum, but people aren’t going to read through extensive topic threads to gain an understanding. A brief summary of what you are doing that pertains to your question is best. And as t-p asks, you need to ask a question!

    I think you wish to filter the terms in the $terms array so that only terms whose name’s first letter is the same as $mo are output. As we’ve discussed previously, this isn’t very efficient. But seeing as you feel that a more efficient approach using custom SQL is beyond your current skill level, this will do for now. At some point as your site grows, you may find this approach takes too long. By then, maybe you’ll have more confidence to tackle SQL ??

    Given all of that, you are close. The if () conditional isn’t constructed quite right. The <?php ?> delimiters and ; terminators aren’t matched up correctly either. And as I’m sure you realize, using a static substr() source of ‘term’ isn’t going to work. You need to supply the current $term object’s name. Because most Linux systems are case sensitive, be sure you are matching up the correct data. Term name could be upper or lower case. You should convert cases for consistency or try to match either or both cases. Is $mo always one or the other? Or can it vary as well?

    It might be better to match the slug’s first letter, which should always be lower case. Assuming slugs match up well with names. Be sure $mo is always lower case as well. Try this as your conditional:
    <?php if ( $term->slug[0] == $mo ) { ?>

    Be sure your other <?php ?> delimiters match up correctly. You do not place ; terminators after { curly braces }. Remove the semi-colons; from the last line.

    I used a shortcut for substr( $term->slug, 0, 1 ) when getting a single character. Strings can be treated as indexed arrays where each character is an array element.

    Thread Starter scottiescotsman

    (@scottiescotsman)

    worked flawlessly.
    I know I am close a lot of the time I just need a little shove ??

    p.s. you are all great here ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘substr error’ is closed to new replies.