0

Im trying to echo out a value grabbed from a ACF field but I think im doing something wrong, could someone help me?

    <div class="news">
    <div class="container">
        <div class="row">
            <?php
                    $selected_cat = get_field( 'select_new_category_for_page' );
                    $args = array('post_type' => 'post',  'posts_per_page' => 1, 'cat' => $selected_cat);
                    $Query = new WP_Query($args); ?>
                    <?php if ( $Query->have_posts() ) : while ( $Query->have_posts() ) : $Query->the_post(); ?>
            <div class="col-md-4 nopadding">
                <div class="box">
                    <h2>Latest News</h2>
                    <h3><?php echo the_time('F, y')?></h3>
                    <p><?php $str = get_the_content(); ?>
                    <?php echo substr($str, 0, 100); ?></p>
                    <a href="<?php echo the_permalink(); ?>">Read More...</a>
                </div>
            </div>
            <div class="col-md-8 nopadding">
                <?php echo the_post_thumbnail(); ?>
            </div>
            <?php endwhile; endif; ?>
        </div>
    </div>
</div>

Im trying to echo the var $selected_cat into my $args for wp_query

Any help is appreciated

1

The "cat" variable need to be an ID of the category. It depends how you configured the ACF field in the backend.

Maybe you should print_r($selected_cat) to see what's inside the variable. it is probably an array with the full information of the category.

  • Yup just your right I clicked return object instead of ID – Tom Withers Feb 26 '16 at 14:03
  • @GuruTom can you mark this as answered? – Jorin van Vilsteren Feb 29 '16 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.