Home Forums General Issues Trimming the field value


Trimming the field value

  • Hi,

    I am using custom field with the select type to let users choose the month of an event. I need to use the value the user chooses twice in my template, once written out and once in another loop in the abbreviated form.

    I thought I could just store the value of the field in a variable and then trim the variable after x number of characters

    $eventmonth = get_field(‘event_month’);

    $args = array(
    ‘post_type’ => ‘post’,
    ‘cat’ => ‘-4’,
    ‘posts_per_page’ => 4
    $the_query = new WP_Query( $args );

    <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <div class=”col-sm-2″>
    <div class=”event-date”>
    <span class=”event-month”><?php substr($eventmonth, 0, 3); ?></span><br/>
    <span class=”event-day”><?php the_field(‘event_day’); ?></span>

    <div class=”col-sm-10″>
    <h2><?php the_title(); ?></h2>
    <p><?php the_excerpt(); ?></p>
    “>Read more
    <?php endwhile; endif; ?>

    it’s not working though and I have no idea why or how to solve the issue. I would be very greateful if anybody could help me fix it and explain what I’m doing wrong

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.