1

I need to put an advanced custom field value (category number) from page to query_posts array. Is it somehow possible?

On a single page I'm trying to show posts from category, which number is value of this custom field.

Ideal and of course non-functional case:

query_posts(array('category__and'=>array( the_field("category"); ,99), 'posts_per_page'=>6));

1 Answer 1

1

the_field() displays a meta value. You'll want to use get_field() (which returns a meta value) instead:

query_posts(array('category__and'=>array( get_field("category"); ,99), 'posts_per_page'=>6));

In somewhat unrelated news, you should really consider avoiding the use of query_posts.

Sign up to request clarification or add additional context in comments.

1 Comment

It works perfect, thanks a lot! And thanks for the tip aswell.

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.