Support

Account

Home Forums ACF PRO Relationship Field Posts – WP_Query Orderby Backend Order

Solved

Relationship Field Posts – WP_Query Orderby Backend Order

  • Hi there

    I have a relationship field which links multiple custom post types and pages in a feature content section on my site home page. In my WP_Query I’m trying to figure out how to order the posts so that they conform to the display order set in the page editor?

      $ids = get_field('feature_content', false, false);
    
      if($ids){
      $args = array(
          'post_type' => 'any',
          'posts_per_page' => 6,
          'post__in' => $ids,
          'post_status' => 'publish',
          'orderby' =>  'menu_order',
          'order' => 'ASC'
      );
      } else{
          $args = array();
      }
  • Ok, I figured this out. Needed to change orderby to ‘orderby’ => ‘post__in’

      if($ids){
      $args = array(
          'post_type' => 'any',
          'posts_per_page' => 6,
          'post__in' => $ids,
          'post_status' => 'publish',
          'orderby' =>  'post__in',
          'order' => 'ASC'
      );
      } else{
          $args = array();
      }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.