1

I have a custom field as an option, and I want to put the value of this option in a custom loop.

So here's what I have:

$CatTxt = the_field('section_1', 'option'); 
            echo $CatTxt;

This works, the problem is when I try to put on the loop. My attempts:

Double quotes - doesn't work:

<?php query_posts("category_name=$CatTxt"); ?>

Separating with the dot - Doesn't' work:

<?php query_posts('category_name='.$CatTxt); ?>

Any idea on how to make this work? Thanks!

1
  • Are you using the ACF plugin? Cause "the_field" function outputs the data. You should be using "get_field" function which returns data and assigns it to a variable. Then combine this with what @Ognjen wrote and it should do the trick. Commented Feb 7, 2016 at 19:55

1 Answer 1

1

Try this now please:

<?php query_posts('category_name='.'"$CatTxt"'); ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.