Home Forums Front-end Issues Orderby link array title


Orderby link array title

  • I have a custom field link array, and I’d like to order the posts by the title of the link array field of each post, but the result doesn’t seem to be ordered. Any help would be much appreciated.

    $args = array(
            'category_name'     => $cat,
    		'posts_per_page'   	=> -1,
    		'order'     		=> 'DSC',
    		'orderby'   		=> 'meta_value',
        	'meta_key' 			=> 'dist_link',
  • What type of field is it? A link field?

    A link field stores an array in the database, there isn’t any way to order posts by this type of field.

    Here is an example of 2 link fields in the db:

    a:3:{s:5:"title";s:9:"ACF Forum";s:3:"url";s:41:"";s:6:"target";s:0:"";}

    You’ll notice that the first thing that is different and will cause the sorting is
    a:3:{s:5:"title";s:9: compared to a:3:{s:5:"title";s:6

    the 9 and 6 are the string lengths of the titles, so they would be sorted in this order. Also 10 would come before 5. Given two link titles of the same length they would be sorted alphabetically.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.