Support

Account

Home Forums General Issues Use ACF Field value in a WP_Query

Unread

Use ACF Field value in a WP_Query

  • Hi,

    So I’m looking to edit a query and have the items output, by alphabetical order, based on a ACF Field I’ve created.

    Here is the query as it stands:

          <?php $term_args = array(
              'post_type' => 'people',
              'posts_per_page' => -1,
              'tax_query' => $tax_query,
              'orderby' => 'title',
           );
           if (isset($s) && $s != '') {
              $term_args['s'] = $s;
          }
          $term_query = new WP_query($term_args);>

    This currently shows based on the page title, from A-Z, as expected.

    Within the custom post type People, I have a field for Surname, which I want to use to show the order from, again from A-Z. I’ve found other examples on here, but they seem to use a date field in ACF, and not a title, so I can’t really apply what I need.

    Is what I’m looking to achieve possible?

    Thanks,

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.