I’m trying to figure out how to define a post as either featured or sticky to display in a different way on my WordPress build.
CPT UI gave me:
add_action('init', 'cptui_register_my_cpt_projects');
function cptui_register_my_cpt_projects() {
register_post_type('projects', array(
'label' => 'Projects',
'description' => 'Add individual projects',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'projects', 'with_front' => true),
'query_var' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
'labels' => array (
'name' => 'Projects',
'singular_name' => 'Project',
'menu_name' => 'Projects',
'add_new' => 'Add Project',
'add_new_item' => 'Add New Project',
'edit' => 'Edit',
'edit_item' => 'Edit Project',
'new_item' => 'New Project',
'view' => 'View Project',
'view_item' => 'View Project',
'search_items' => 'Search Projects',
'not_found' => 'No Projects Found',
'not_found_in_trash' => 'No Projects Found in Trash',
'parent' => 'Parent Project',
)
) ); }
I tried adding in 'meta_key' => 'Sticky', & 'meta_key' => 'on',
however neither were successful.
How would I go about adding an option to the front end of each post to make it featured or sticky?
As far as I’m aware custom post types are not supported for sticky posts. However I managed to get around it with this function.
This will add a meta checkbox in all CPT posts that will say ‘Sticky’ and will float to the top in that CPT archive