You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为CPT UI创建的自定义文章类型添加特色文章星标按钮?

How to Add the Sticky Post Star Button to Your Custom Post Type (Promotions)

Hey there! I totally get the frustration coming from Drupal to WordPress and hitting little hurdles like this—let’s get that star button showing up for your promotions custom post type right away.

There are two straightforward ways to fix this, depending on whether you want to use the CPT UI plugin interface or add a bit of code:

Option 1: Use CPT UI to Enable Sticky Support Directly

If you built the post type with CPT UI, you can toggle this setting right in the plugin:

  • Head to your WordPress admin sidebar, go to CPT UI > Edit Post Types
  • Find your promotions post type in the list and click the Edit button next to it
  • Scroll down to the Supports section (this controls which default WordPress features your post type uses)
  • Look for the Sticky option (it might be labeled "Sticky Posts" or just "Sticky") and check the box
  • Save your changes, then refresh the promotions list page (wp-admin/edit.php?post_type=promotions)—the star button should now appear next to each post, just like with default posts.

Option 2: Add Sticky Support via Code (If CPT UI Doesn’t Show the Option)

Sometimes CPT UI’s interface might not display the sticky option, or you might prefer to set this via code for better control. Here’s how:

  • Open your theme’s functions.php file (or use a plugin like Code Snippets to add custom code without editing theme files directly)
  • Paste this snippet:
// Enable sticky post support for the promotions custom post type
add_action('init', 'add_sticky_support_to_promotions');
function add_sticky_support_to_promotions() {
    add_post_type_support('promotions', 'sticky');
}
  • Save the changes, then go back to your promotions list page. The star button will be there ready to use!

A quick note: If you want these sticky promotions to show up at the top of your front-end lists (like how sticky posts work for default posts), you’ll need to adjust your custom queries to include 'post__in' => get_option('sticky_posts') and set 'ignore_sticky_posts' => false, but that’s an extra step if you need it. For just the admin star button, the above steps are all you need.

内容的提问来源于stack exchange,提问作者dmegatool

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 21:07:53