Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:10up/simple-page-ordering into u…
Browse files Browse the repository at this point in the history
…pkeep/102
  • Loading branch information
Sidsector9 committed Nov 2, 2022
2 parents 44431c8 + c54f7f3 commit 941d352
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 293 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Yep. When you register the post type, include the `page-attributes` feature in t

`'supports' => array( 'title', 'editor', 'page-attributes' ),`

Alternatively, when you register the post type, set `hierarchical` to `true` - hierarchical post types natively order by menu order.

You can also take advantage of the `simple_page_ordering_is_sortable` filter, which passes the result of the default check and the post type name, to override default behavior.

### I want my non-hierarchical post type to be sortable. Help!
Expand All @@ -60,11 +62,11 @@ Where 5 is the number of items to batch on each request (the default is 50). Not

This feature is already built into WordPress natively, but a bit tucked away. If you pull down the "Screen Options" tab up top (on the list of post objects) there's a field where you can specify the number of items to show per page. I decided it was not a very good practice to duplicate this.

### How can I exclude certain custom post types?
### How can I modify sortable post types?

Custom post types can be excluded by using the `simple_page_ordering_is_sortable` filter.
Post types can be included or excluded by using the `simple_page_ordering_is_sortable` filter.

For example, with `excluded_post_type` as the custom post type ID, add the following snippet in the theme function file or custom plugin:
For example, to exclude the `excluded_post_type` custom post type, add the following snippet in the theme function file or custom plugin:

```
add_filter( 'simple_page_ordering_is_sortable', function( $sortable, $post_type ) {
Expand All @@ -75,6 +77,17 @@ add_filter( 'simple_page_ordering_is_sortable', function( $sortable, $post_type
}, 10, 2 );
```

To include the `include_post_type` custom post type, add the following snippet in the theme function file or custom plugin:

```
add_filter( 'simple_page_ordering_is_sortable', function( $sortable, $post_type ) {
if ( 'include_post_type' === $post_type ) {
return true;
}
return $sortable;
}, 10, 2 );
```

### Can I use REST to order posts?

Yes. The plugin registers the REST endpoint `simple-page-ordering/v1/page_ordering`.
Expand Down
Loading

0 comments on commit 941d352

Please sign in to comment.