FilT FilT - 23 days ago 8
PHP Question

Featured custom post type slider

I have a custom-post-type and I want to display a featured slider in my homepage with some of those custom posts.

I want to create a metabox to select if it's a featured post or not and only then display it.

This is the code that I have, which is not working as to add a metabox.

<?php function sm_custom_meta() {
add_meta_box( 'sm_meta', __( 'Featured Posts', 'sm-textdomain' ), 'sm_meta_callback', 'post' );
}
function sm_meta_callback( $post ) {
$featured = get_post_meta( $post->ID );
?>

<p>
<div class="sm-row-content">
<label for="meta-checkbox">
<input type="checkbox" name="meta-checkbox" id="meta-checkbox" value="yes" <?php if ( isset ( $featured['meta-checkbox'] ) ) checked( $featured['meta-checkbox'][0], 'yes' ); ?> />
<?php _e( 'Featured this post', 'sm-textdomain' )?>
</label>

</div>
</p>

<?php
}
add_action( 'add_meta_boxes', 'sm_custom_meta' );
?>


I'm following the steps in this post and it's not working http://smallenvelop.com/how-to-create-featured-posts-in-wordpress/

I don't want to use any plugins.

I've changed the sm-textdomain to my theme name, and the 'post' to my slug-post-type.

Can you figure out what I'm doing wrong and help out?

Thanks.

Answer

check if you have other arrays or queries in the page, and since you mentioned it's a CPT, check if the query is looking in the post_type=>slug