Auto Slug Generation for Custom Post type

You can achieve this using the save_post hook. For example if you have a custom post type stack, the hook can be changed to save_post_stack. To set the post-slug to the first few words of the content: add_action( ‘save_post_stack’, ‘wpse251743_set_title’, 10, 3 ); function wpse251743_set_title ( $post_id ){ //This temporarily removes action to prevent infinite … Read more

single-{post_type}.php not working

according to your code, your cpt is “event”. You will either need to change the your php to single-event.php or change this line: register_post_type(‘event’, $args); to register_post_type(‘events’, $args); Usually they are the plural so the 2nd option is a better choice. With that being said, I always recommend adding namespace to avoid conflicts. Especially in … Read more

Detect inside a custom query the kind of post type to assign custom classes

The post_class function will do this for you automatically within the loop: <div <?php post_class(); ?>> which will add some combination of these classes: .post-[id] .[post-type] .type-[post-type] .status-[post-status] .format-[post-format] (default to ‘standard’) .post-password-required .post-password-protected .has-post-thumbnail .sticky .hentry (hAtom microformat pages) .[taxonomy]-[taxonomy-slug] (includes category) .tag-[tag-name] You can also get just the post type within the loop … Read more

Post to Top in Array

You sure can, just order them by the meta_field, like in this example $posts = get_posts(array( ‘post_type’ => ‘post_type’, //The slug of your post type ‘posts_per_page’ => -1, ‘meta_key’ => ‘meta_key’, // The name of your field ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ // Will put the higher values first )); Learn more in the … Read more

Sort posts in loop by the WooCommerce Membership of the author

I would flag post as member_post when it is submitted to database and use this flag to sort them. function wpse_287048_flag_member_post( $post_id ) { if ( wc_memberships_get_user_active_memberships() !== false ) { // Check if user is member update_post_meta( $post_id, ‘member_post’, 1 ); } else { update_post_meta( $post_id, ‘member_post’, 0 ); } } add_action( ‘save_post’, ‘wpse_287048_flag_member_post’ … Read more

Show ACF to front end custom post [closed]

You have to get familiar with template hierarchy to understand in which template WordPress will display your custom post type. If you have sample custom post type named event with title Lorem ipsum, WordPress will watch for this files in that order in your theme to display such a custom post type: single-$post_type-$slug.php for our … Read more