Sticky CPT
Sticky CPT
Description
The plugin allows to highlight the CPT in the same way as would the WordPress core functionality for posts.
You can highlight new content created for your CPT.
It is also possible to highlight the content quickly thanks to quick edit and bulk actions.
The sticky checkbox is available in the block editor, in the classic editor, in quick edit and in bulk edit, for every public custom post type.
Sticky items are stored in the core sticky_posts option, exactly like sticky posts: is_sticky() works out of the box.
Start example
$args = array(
'post_type' => ['project'],
'post_status' => 'publish',
'posts_per_page' => -1,
'post__in' => get_option( 'sticky_posts' )
);
$stickyProject = new WP_Query( $args );
Hook available
add_filter( 'sticky_cpt_add_cpt' , 'add_cpt' );
function add_cpt( $post_types ) {
$post_types['newcpt'] = 'newcpt';
return $post_types;
}
Installation
- Upload the plugin files to the
/wp-content/plugins/sticky-cptdirectory, or install the plugin through the WordPress plugins screen directly. - Activate the plugin through the ‘Plugins’ screen in WordPress
Faq
No. Since 3.0.0 the block editor uses the native sticky field of the REST API. Your custom post type only needs show_in_rest to use the block editor.
Users who can both publish and edit others’ contents of the custom post type, the same rule WordPress applies to posts.
This meta was removed in 3.0.0. Use is_sticky( $post_id ) or get_option( 'sticky_posts' ) instead.
Enable “Sticky posts” in the Polylang synchronization settings. Until 2.0.0 the sticky state was carried by a custom field, so it followed the “Custom fields” synchronization. Since 3.0.0 it only follows the “Sticky posts” synchronization.
When the Polylang “Sticky posts” synchronization is enabled, a bulk edit that leaves the “Sticky” field on “No Change” unsticks the edited contents and their translations. This comes from Polylang (observed with Polylang 3.8.10) and also affects regular posts, with or without this plugin. Until it is fixed in Polylang, select “Sticky” explicitly in the bulk edit form when all the selected contents are sticky, or stick them again afterwards.
Reviews
Good job! (small feature request inside)
By Jb Audras (audrasjb) on March 2, 2017
load_plugin_textdomain() function is missing, as well as the language textdomain metadata in the plugin main file comments, and a better use of WP translation strings 😉
E.g : instead of __( "Make this post sticky" ), you should rather use __( "Make this post sticky", "sticky-cpt" )
But very nice work by the way, as usual 🙂4.7.2 works (with cpt ui)
By Chris (eskim0) on February 27, 2017
Changelog
3.0.0
- Rewrite: the sticky state now relies on the native
stickyREST field, thecustom-fieldssupport is no longer required for the block editor. - Breaking: the
sticky_value_cptpost meta is removed and deleted on update. Useis_sticky()or thesticky_postsoption. - Breaking: with Polylang, the sticky state no longer follows the “Custom fields” synchronization. Enable the “Sticky posts” synchronization instead.
- Security: only users allowed to publish and edit others’ contents of the post type can stick or unstick a content.
- Fix: a sticky content is no longer unstuck when it is saved from the block editor with meta boxes, or from quick edit on hierarchical post types.
- Fix: duplicated IDs in the
sticky_postsoption and wrong sticky counter. - Fix: stray text printed in the classic editor footer.
- Performance: the sticky counter of the list screen no longer loads every ID of the post type.
- Block editor script migrated to
wp.editor.PluginPostStatusInfo. - Requires WordPress 6.6 and PHP 8.2. Tested with WordPress 7.1.
2.0.0
- 19 march 2020
- Gutenberg compatibility
1.0.1
- 04 july 2017
- Add contributor Whodunit and Check compatibility WordPress 4.8
1.0.0
- 22 oct 2016
- Initial release \o/

