Skip Navigation

[Resolved] Cannot Sort Fields On Edit All Posts Dashboard Page (/wp-admin/edit.php)

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

This thread is resolved. Here is a description of the problem and solution.

Problem: Sorting by date does not appear to work as expected in the wp-admin area for a custom post type.

Solution: Adjust theme files if necessary to make sure Admin pages are not effected (!is_admin()) by sorting options set for the front-end.

//Plants Archive Page Sorting 
function plants_archive_change_sort_order($query) {
    if (!is_admin() && is_post_type_archive('plants')) {
        //Set the order ASC or DESC
        $query->set( 'order', 'ASC' );
        //Set the orderby
        $query->set( 'orderby', 'name' );
    }   
}
add_action( 'pre_get_posts', 'plants_archive_change_sort_order');

Relevant Documentation:

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 9 replies, has 3 voices.

Last updated by Christian Cox 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#526258
Screen Shot 2017-05-19 at 11.14.14 AM.png

I am trying to: Sort Posts by Date.

I visited this URL: hidden link

I expected to see: The posts in order of date, descending.

Instead, I got: Default sort.

On my dev environment with only Types installed as a plugin, this still happens. I have a code-based custom post type, "Gifts". This post type does not have the same issue.

#526289

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Peter,

Thank you for contacting our support forum.

I tried this on a test install that I had and it works perfectly fine. This is the default publish date field from wordpress correct?

Would you mind providing me with admin access to the website so that I can have a look at this for you?

Thanks,
Shane

#527225

I also noticed that I can go to another custom post type, and sort columns. For example, Bamboo.

#527254

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Peter,

I'm not sure what is causing the issue here but would you mind if I install the duplicator plugin and create a duplicator package of this website for further testing ?

Thanks,
Shane

#527442

Shane, go ahead.

#527668

Hi, Shane is off today so I will take over this ticket. I hope that's okay. If I temporarily enable a default theme, like Twenty Seventeen, sorting of Plants works as expected. Can you confirm this behavior on the staging site? If you agree, then it seems we have a theme compatibility issue.

#527695

Yes, I agree. I will look through the theme to find an answer. Thank you!

#527699

Thanks, keep me posted. If you're unable to find anything, I can escalate this ticket to our compatibility team to see if they have any ideas.

#527701

I found the code that was causing the issue:

//Plants Archive Page Sorting 
function plants_archive_change_sort_order($query) {
	if (is_post_type_archive('plants')) {
		//Set the order ASC or DESC
		$query->set( 'order', 'ASC' );
		//Set the orderby
		$query->set( 'orderby', 'name' );
	}   
}
add_action( 'pre_get_posts', 'plants_archive_change_sort_order');

I changed it to this:

//Plants Archive Page Sorting 
function plants_archive_change_sort_order($query) {
	if (!is_admin() && is_post_type_archive('plants')) {
		//Set the order ASC or DESC
		$query->set( 'order', 'ASC' );
		//Set the orderby
		$query->set( 'orderby', 'name' );
	}   
}
add_action( 'pre_get_posts', 'plants_archive_change_sort_order');

And we're set! I didn't realize that this action would happen in the Dashboard, as well...

#527702

Nice!

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.