0

I am trying to set category_name of a query using an ACF text field but I am getting all posts instead the post of the category I want.

          $category1 = the_field('category1');
          $args1=array(
            'posts_per_page' => 3,
            'post_type'      => 'post',
            'post_status'   => 'publish',
            'category_name' => $category1,
            );

Does anybody have any solution on that?

Thanks

1 Answer 1

1

the_field is used to output, get_field is used to return.
So instead of

$category1 = the_field('category1');

It should be

$category1 = get_field('category1');
1
  • you are absolutely right! I totally missed that. Thanks
    – Bill
    Feb 22, 2022 at 13:04

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.