Support

Account

Home Forums General Issues Sort by ACF field not working properly

Unread

Sort by ACF field not working properly

  • Hi,
    i am trying to sort by an ACF field which is (for the time being) an exact copy of the Title field :
    It’s called acf_journaltitle_slug
    I have a WP query that returns the results and renders them to DataTables.
    When the WP query is sorted by title everything works fine (see attache image 2).
    When i use

    $args_journals = array(
            'post_type' => 'journal',
            'post_status' => 'publish',
            'posts_per_page' => $request['length'],
            'offset' => $request['start'],
            'order' => $request['order'][0]['dir'],
    		'starts_with' => $rq_letter
    		);
    		
    	
    		
    		if ($request['order'][0]['column'] == 0) {
    			$args_journals['meta_key'] = 'acf_journaltitle_slug';
    			$args_journals['orderby'] = 'meta_value';
    			
    			$args_journals['order'] = 'ASC';
    			
    			
    			} elseif ($request['order'][0]['column'] == 1 ){
    			
    			$args_journals['orderby'] = 'title';
    			//$args_journals['orderby'] = 'acf_journaltitle_slug';
    			
    			
    			
    		}

    the results are ordered kind of randomly (see attached image 3)
    Why does that happen??

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.