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">
                    $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 class="col-md-8 nopadding">
                <?php echo the_post_thumbnail(); ?>
            <?php endwhile; endif; ?>

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

Any help is appreciated

1 Answer 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 Commented Feb 26, 2016 at 14:03
  • @GuruTom can you mark this as answered? Commented Feb 29, 2016 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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