Home Forums Backend Issues (wp-admin) Page Link – Order by date NOT title?


Page Link – Order by date NOT title?

  • Hi Guys

    Was just wondering if there’s anyway we could order the Page Link custom field by date? at the moment they’re ordered alphabetically by title.


  • That depends on if you’re allowing only one post type and if that post type is hierarchical or not.

    If you you’re allowing multiple posts types or the post type is hierarchical, then no. The reason is that ACF groups the posts according to post type and parent page. Attempting to reorder them by date will cause the results to be broken.

    If you are limiting it to a single post type and it is not hierarchical then the answer is a definite maybe. There are filters that you can use set the WP_Query args and you can change the order by.

    Line 144 of /fields/page_link.php, I don’t think these filters are documented.

    // filters
    $args = apply_filters('acf/fields/page_link/query', $args, $field, $options['post_id']);
    $args = apply_filters('acf/fields/page_link/query/name=' . $field['name'], $args, $field, $options['post_id'] );
    $args = apply_filters('acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id'] );

    I have not tested this.

                     'change_page_link_order_by', 10, 3);
    function change_page_link_order_by($args, $field, $post_id) {
      $args['orderby'] = 'date';
      $arge['order'] = 'DESC';
      return $args;
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Page Link – Order by date NOT title?’ is closed to new replies.