• Resolved Jackie Chan

    (@jackie-chan)


    Hi,

    I’ve created a custom post type; is it possible to register it so it behaves as a standard post?

    For example: my theme has a post slider module with the options to choose which categories to display, how would my custom post type category appear in that list?

    I’m guessing that would be the easiest way rather than trying to code my custom post type directly into the slider module, any advice?

    Thanks ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Start by asking the developers of your theme. If there’s not an option, then you’d probably need to modify the behavior of the slider via a pre_get_posts() hook into the query used by the slider to get posts. Without more information, I can’t really be more specific.

    Thread Starter Jackie Chan

    (@jackie-chan)

    Hi Steve, thanks for your reply; the theme developer (Elegant Themes) wasn’t very helpful. I’ve almost done it with the code below, which allows me to choose the category from within my slider module but i’m getting this within the slider:

    “No Results Found
    The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.”

    This is the code to include the category:

    add_filter('pre_get_posts', 'query_post_type');
    function query_post_type($query) {
      if( is_category() ) {
        $post_type = get_query_var('post_type');
        if($post_type)
            $post_type = $post_type;
        else
            $post_type = array('nav_menu_item', 'post', 'country_walks'); // don't forget nav_menu_item to allow menus to work!
        $query->set('post_type',$post_type);
        return $query;
        }
    }

    Is adding a taxonomies essential to the custom post type as i’ve not done this..

    Here’s my post type code:

    function cptui_register_my_cpts_country_walks() {
    
    	/**
    	 * Post Type: Country Walks.
    	 */
    
    	$labels = [
    		"name" => __( "Country Walks", "custom-post-type-ui" ),
    		"singular_name" => __( "Walks", "custom-post-type-ui" ),
    		"view_item" => __( "View Page", "custom-post-type-ui" ),
    		"view_items" => __( "View Walks", "custom-post-type-ui" ),
    	];
    
    	$args = [
    		"label" => __( "Country Walks", "custom-post-type-ui" ),
    		"labels" => $labels,
    		"description" => "",
    		"public" => true,
    		"publicly_queryable" => true,
    		"show_ui" => true,
    		"show_in_rest" => true,
    		"rest_base" => "",
    		"rest_controller_class" => "WP_REST_Posts_Controller",
    		"has_archive" => false,
    		"show_in_menu" => true,
    		"show_in_nav_menus" => true,
    		"delete_with_user" => false,
    		"exclude_from_search" => false,
    		"capability_type" => "post",
    		"map_meta_cap" => true,
    		"hierarchical" => false,
    		"rewrite" => [ "slug" => "country_walks", "with_front" => true ],
    		"query_var" => true,
    		"supports" => [ "title", "editor", "thumbnail", "excerpt", "custom-fields", "page-attributes", "post-formats" ],
    		"taxonomies" => [ "category" ],
    	];
    
    	register_post_type( "country_walks", $args );
    }
    
    add_action( 'init', 'cptui_register_my_cpts_country_walks' );
    
    • This reply was modified 4 years, 10 months ago by Jackie Chan.
    • This reply was modified 4 years, 10 months ago by Jackie Chan.
    • This reply was modified 4 years, 10 months ago by Jackie Chan.
    • This reply was modified 4 years, 10 months ago by Jackie Chan.
    • This reply was modified 4 years, 10 months ago by Jackie Chan.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    You’re using a commercial theme, so please use their official support channel. We feel they are best equipped to support their products.

    https://www.elegantthemes.com/members-area/help/

    Commercial products are not supported in these forums.

    Thread Starter Jackie Chan

    (@jackie-chan)

    Thanks Steve, their support is good for the basics but anything slightly more tricky they refuse to help which is why i’ve reverted back to good ol’ WP support.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Register Custom Post Type as Standard Posts’ is closed to new replies.