• Resolved dzulfriday

    (@dzulfriday)


    I have many custom post types on my website.
    How can I exclude a custom post type from using the plugin page ordering?

    I want a custom post type to sort by the latest date, but others still use the plugin page ordering.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @dzulfriday,

    You can use this code to exclude specific post types

    
    add_filter( 'simple_page_ordering_is_sortable', function( $sortable, $post_type ) {
    	if( 'excluded_post_type' === $post_type ) {
    		return false;
    	}
    	return $sortable;
    }, 10, 2 );
    
    
    Thread Starter dzulfriday

    (@dzulfriday)

    Thanks,

    It works.

    Hi,

    Could you give an example of how to use the code? Which element of the code should be replaced with custom post type name?

    Hi @atheneit,

    You can append the snippet above to your theme’s functions.php (at the end of the file). Then replace excluded_post_type by your post type’s id.

    Hope this help!

    Thread Starter dzulfriday

    (@dzulfriday)

    This is works for only one custom post type, what if I want to exclude 2 or 3 custom post types?

    @dzulfriday You can use in_array to check for multiple post types. For example:

    
    ...
    if ( in_array( $post_type, [ 'post_type_1', 'post_type_2' ], true ) ) {
    ...
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Exclude certain custom post type’ is closed to new replies.