Add categories to a page with out using Custom Post Types

If you don’t want to attach the default post category taxonomy, you can always create a new one specifically for pages. Insert this into your functions.php file: add_action( ‘init’, ‘create_page_taxonomies’ ); function create_page_taxonomies() { register_taxonomy(‘page_category’, ‘page’, array( ‘hierarchical’ => true, ‘labels’ => array( ‘name’ => _x( ‘Page Category’, ‘taxonomy general name’ ), ‘singular_name’ => _x( … Read more

detect your custom post type in WordPress

are you looking for get_post_type? You can use it to get any CPT type by slug and use it conditionally For instance: function filter_the_content( $content ) { if ( ! is_user_logged_in() && ‘my_cpt’ == get_post_type() ) { return “Content reserved to logged in users”; } return $content; } add_filter( ‘the_content’, ‘filter_the_content’ ); The docs: https://developer.wordpress.org/reference/functions/get_post_type/

Exclude current post for custom post type

You should use get_queried_object() or get_queried_object_id() to get the current custom post’s ID. IMO get_queried_object() is a better choice here as you can conditionaly check for the post type also. Try this function wpse258217_random_posts() { $obj = get_queried_object(); if ( $obj->post_type === ‘question’ ) { $postid = $obj->ID; $my_query = new WP_Query( array(‘showposts’ => ‘8’, … Read more

Sort a custom post with ACF: Date Picker & Display Featured!

Please change your args like this. $meta_query = array( array( ‘key’ => ‘event_type’, ‘value’ => ‘featured’, ‘compare’ => ‘=’ ) ); $args = array( ‘post_type’ => ‘event’, ‘posts_per_page’ => -1, ‘order’ => ‘DESC’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘event_date’, ‘meta_query’ => $meta_query );