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

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.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

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:

Related documentation: WordPress Custom Post Types

This topic contains 9 replies, has 3 voices, and was last updated by  Christian Cox 2 months ago. The support staff assigned to this topic is Christian Cox.

Viewing 10 posts - 1 through 10 (of 10 total)
Author
Posts
#526258

I am trying to: Sort Posts by Date.

I visited this URL: http://cactusjungle.com/wp-admin/edit.php?post_type=plants&orderby=date&order=desc

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
Forum moderator

Supporter languages: English (English )

Supporter 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
Forum moderator

Supporter languages: English (English )

Supporter 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

Christian Cox
Forum moderator

Supporter languages: English (English )

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

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

Christian Cox
Forum moderator

Supporter languages: English (English )

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

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

Christian Cox
Forum moderator

Supporter languages: English (English )

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

Nice!

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

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Known issues and their solutions

We document known issues and their solutions in Toolset erratas. Save time by checking there first and seeing if what you are facing is a known issue. This list is kept short. We do our best to resolve all known issues with every release of Toolset plugins.

Support Policy

Toolset staff will help you use the Toolset plugins correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

For more information, read our full Customer Support Policy.

Need custom programming work for your site? Check out our certified partners.