Lucas Haas
Lucas Haas

Reputation: 341

Echo PHP variable under a Wordpress custom Query

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!

Upvotes: 1

Views: 198

Answers (1)

Ognjen Babic
Ognjen Babic

Reputation: 119

Try this now please:

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

Upvotes: 1

Related Questions